【发布时间】:2011-06-07 22:55:30
【问题描述】:
我知道这是一个经常被问到的问题/问题。针对我的问题,我查看了一堆问答,但我想我有点厚,因为我在任何地方都没有看到答案。
我有一个包含在数组中的文件,我想用它来填充 tableView。
问题是它没有被调用。 numberOfRowsInSection 或 numberOfSectionsInTableView 都不是。据我所知,只调用了 viewDidLoad。
我有 1 个部分,我的数组中的元素数等于 3(而不是 nil)。
相关代码在这里...
- (void)viewDidLoad {
[super viewDidLoad];
FileControl *fileArray = [[FileControl alloc] init];
matArray = [fileArray findUniqueItemsInArray:0 :[fileArray setFileToArray]];
[fileArray release];
NSLog(@"%i \n %@", [matArray count], matArray); // matArray is filled.
NSLog(@"ViewDidLoad"); }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSLog(@"CellForRowAtIndexPath");
NSString *text = [matArray objectAtIndex:[indexPath row]];
[[cell textLabel] setText:text];
return cell; }
@interface MaterialTableViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *materialTableView;
NSArray *matArray;
}
@property (nonatomic, retain) NSArray *matArray;
@end
其他方法都是标准的。
我想我的问题在于我对流程的理解不够好。
任何帮助将不胜感激。提前致谢。
【问题讨论】:
-
从
viewDidLoad方法调用[tableView reloadData];会导致表格视图更新吗? -
matArray 是 NSArray 类型;您正在将 FileControl 类型分配给 NSArray ?尝试更改其中任何一个。
标签: iphone objective-c uitableview nsarray