如何在UITableView ios中显示数据



开发一个iPAD应用程序,我试图在其中填充表,我就是这样做的:在视图已加载的情况下,我正在创建两个dictionary对象,并将对象添加为Pdf和Excel。

- (void)viewDidLoad
{
[super viewDidLoad];
arrDocuments = [[NSMutableArray alloc] init];
NSArray *arr1 = [NSArray arrayWithObjects:@"PDF", nil];
NSDictionary *pdf = [NSDictionary dictionaryWithObjects:arr1 forKeys:nil];
NSArray *arr2 = [NSArray arrayWithObjects:@"Excel", nil];
NSDictionary *excel = [NSDictionary dictionaryWithObjects:arr2 forKeys:nil];
[arrDocuments addObject:pdf];
[arrDocuments addObject:excel];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
  return [arrDocuments count]; 
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
//return [arrReceipes count];
NSDictionary *dictionary = [arrDocuments objectAtIndex:section];
NSArray *array = [dictionary objectForKey:[self.sortedKeys objectAtIndex:section]];
return [array count];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableView *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell ==nil) {
   cell = [[UITableViewCell alloc]initWithFrame:CGRectZero reuseIdentifier:MyIdentifier];
}
return cell;
}

使用此实现,我无法看到表视图。它将转到main方法,并向我显示SIGABRT消息。我哪里错了??

在创建NSDictionary时,您传递了nil来代替密钥数组

 NSDictionary *pdf = [NSDictionary dictionaryWithObjects:arr1 forKeys:nil];

你应该给字典正确的对象和关键字。该方法期望在数组中给定对象和键,正如您在其方法签名中看到的那样。

+ (instancetype)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys

最新更新