objective-c

C code posted by me
created at 19 Nov 10:48, updated at 19 Nov 11:28

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#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
2.51 KB in 4 ms with coderay