【问题标题】:How to show Data in UITableView ios如何在 UITableView ios 中显示数据
【发布时间】:2013-11-25 13:15:46
【问题描述】:

开发一个 iPAD 应用程序,我试图在其中填充表格,这就是我正在做的事情: 在视图确实加载时,我正在创建两个字典对象并将对象添加为 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;
}

有了这个实现,我看不到表格视图。它进入主方法并向我显示 SIGABRT 消息。我哪里出错了??

【问题讨论】:

  • 在 cellForRowAtIndexPath 添加:cell.textLabel.text = ...
  • 您实际上是在哪里创建表格视图的?
  • @llario,智能没有显示“cell.textLable.text”,当我写这个时,它显示的 textLable 没有被识别..
  • 发布任何 NSLog in 方法并检查应用程序崩溃的位置..
  • 这个 self.sortedkeys 是什么?

标签: ios objective-c ipad uitableview


【解决方案1】:

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

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

您应该为字典提供适当的对象和键。如您在其方法签名中所见,此方法期望在数组中给出对象和键。

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

【讨论】:

    猜你喜欢
    • 2016-02-13
    • 1970-01-01
    • 1970-01-01
    • 2013-05-17
    • 2012-08-10
    • 1970-01-01
    • 1970-01-01
    • 2013-12-11
    • 1970-01-01
    相关资源
    最近更新 更多