Title / Description
Code #import "AppDelegate.h" #import "MyListViewCell.h" //test #pragma mark Constants #define LISTVIEW_CELL_IDENTIFIER @"MyListViewCell" #define NUM_EXAMPLE_ITEMS 10 @implementation AppDelegate #pragma mark - #pragma mark Init/Dealloc -(void) awakeFromNib { [listView setCellSpacing: 2.0f]; //[listView setAllowsEmptySelection: YES]; [listView setAllowsMultipleSelection: YES]; [listView registerForDraggedTypes: [NSArray arrayWithObjects: NSStringPboardType, nil]]; _listItems = [[NSMutableArray alloc] init]; // Create a bunch of rows as a test: for( NSInteger i = 0; i < NUM_EXAMPLE_ITEMS; i++ ) { NSString *title = [[NSString alloc] initWithFormat: @"Item %d", i +1]; // We're in a tight loop [_listItems addObject: title]; [title release]; } [listView reloadData]; } - (void)dealloc { [_listItems release]; [super dealloc]; } #pragma mark - #pragma mark List View Delegate Methods - (NSUInteger)numberOfRowsInListView: (PXListView*)aListView { #pragma unused(aListView) return [_listItems count]; } - (PXListViewCell*)listView:(PXListView*)aListView cellForRow:(NSUInteger)row { MyListViewCell *cell = (MyListViewCell*)[aListView dequeueCellWithReusableIdentifier:LISTVIEW_CELL_IDENTIFIER]; if(!cell) { cell = [[[MyListViewCell alloc] initWithReusableIdentifier:LISTVIEW_CELL_IDENTIFIER] autorelease]; } // Set up the new cell: [cell setTitle: [_listItems objectAtIndex: row]]; return cell; } - (CGFloat)listView:(PXListView*)aListView heightOfRow:(NSUInteger)row { #pragma unused(aListView) #pragma unused(row) return 50; } // The following are only needed for drag'n drop: - (BOOL) listView: (PXListView*)aListView writeRowsWithIndexes: (NSIndexSet *)rowIndexes toPasteboard: (NSPasteboard *)dragPasteboard { #pragma unused(aListView) #pragma unused(rowIndexes) // +++ Actually drag the items, not just dummy data. [dragPasteboard declareTypes: [NSArray arrayWithObjects: NSStringPboardType, nil] owner: self]; [dragPasteboard setString: @"Just Testing" forType: NSStringPboardType]; return YES; } - (NSDragOperation) listView: (PXListView*)aListView validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSUInteger)row proposedDropHighlight: (PXListViewDropHighlight)dropHighlight; { #pragma unused(aListView) #pragma unused(info) #pragma unused(row) #pragma unused(dropHighlight) return NSDragOperationCopy; } - (IBAction) reloadTable: (id)sender { #pragma unused(sender) [listView reloadData]; } @end
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code