2013-11-25 12 views
-2

開發一個iPad應用程序,在這裏我想填充表顯示的數據,這纔是我應該怎麼做的: 鑑於沒有負荷,我創建了兩個字典對象,並添加對象爲PDF和Excel。如何在UITableView的IOS

- (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; 
} 

有了這個實現,我不能看到表view.Its將主要方法,並顯示我SIGABRT message.Where我會錯了?

+0

in cellForRowAtIndexPath add:cell.textLabel.text = ... – Ilario

+0

你究竟在哪裏創建了表視圖? –

+0

@llario,該intellisence沒有顯示「cell.textLable.text」,當我在寫這一點,其顯示textLable不辨.. – bapi

回答

0

在創建NSDictionary,你已經通過零到位按鍵排列的,

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

你應該給合適的對象和鍵到詞典中。這個方法需要在數組中給出對象和關鍵字,就像你在其方法簽名中看到的一樣。

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