我在viewcontroller.h設置的NSMutableArray在viewontrolller.m2 problms與numberOfRowsInSection和的cellForRowAtIndexPath
barcodeArray = [[NSMutableArray alloc] init];
這樣的:
@interface SecondViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
NSString *string;
NSString *barcode;
NSArray *array;
NSMutableArray *barcodeArray;
}
比我添加對象是這樣的:
if ([barcodeArray indexOfObject:barcode] != NSNotFound) {
NSLog(@"%@",barcode);
NSLog(@"object zit er al in");
}
else {
[barcodeArray addObject:barcode];
[_tableView reloadData];
NSLog(@"%@",barcodeArray);
NSLog(@"object zit er nog niet in");
}
當我設置numberOfRowsInSection返回[barcodeArray count];函數cellForRowAtIndexPath不被調用。這就像barcodeArray計數爲null。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [barcodeArray count];
}
當我設置numberofRowsinSection返回1;只是爲了測試..我在它那裏得到與(空)單元:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"aangeroepen");
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
cell.textLabel.text = [NSString stringWithFormat:@"%@",[barcodeArray objectAtIndex:indexPath.row]];
NSLog(@"%@", cell.textLabel.text);
return cell;
}
這裏是我的日誌:
2013-01-17 07:57:04.139 Scanner[21865:c07] (
123456
) **// NSMutableArray when i add the barcode**
2013-01-17 07:57:04.140 Scanner[21865:c07] object zit er nog niet in
2013-01-17 07:57:05.485 Scanner[21865:c07] viewdidload
2013-01-17 07:57:05.488 Scanner[21865:c07] aangeroepen
2013-01-17 07:57:05.489 Scanner[21865:c07] (null) **// NSMutableArray in cell.textLabel.text**
編輯:
cell.textLabel.text = [NSString stringWithFormat:@"%@",[barcodeArray objectAtIndex:indexPath.row]];
NSLog(@"celltext:%@", cell.textLabel.text);
NSLog(@"barcodearray%@", [barcodeArray objectAtIndex:indexPath.row]);
NSLog(@"objectatindex:0:%@", [barcodeArray objectAtIndex:0]);
NSLog(@"indexpath.row:%d", indexPath.row);
Log:
2013-01-17 08:27:28.838 Scanner[21978:c07] celltext:(null)
2013-01-17 08:27:28.839 Scanner[21978:c07] barcodearray(null)
2013-01-17 08:27:28.839 Scanner[21978:c07] objectatindex:0:(null)
2013-01-17 08:27:28.839 Scanner[21978:c07] indexpath.row:0
你在做什麼'barcodeArray = [[NSMutableArray alloc] init];'?你可以在該語句中放置斷點或日誌消息嗎?它可能沒有被執行。 – jrturton
我想我的發送方法是錯誤的。我要去嘗試這個方法:http:// stackoverflow。com/questions/5210535/passing-data-between-view-controllers –