2012-06-09 26 views
0

嗨,我在這裏有此代碼。如何更改UITableView單元高度並顯示detailedTextLabel?

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    jsonURL = [NSURL URLWithString:@"http://oo.mu/json2.php"]; 
    jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL usedEncoding:nil error:nil]; 
    self.jsonArray = [jsonData JSONValue]; 

    // Do any additional setup after loading the view, typically from a nib. 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [jsonArray count]; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return [indexPath row] * 20; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
    } 

    cell.textLabel.text = [[self.jsonArray objectAtIndex:indexPath.row] objectForKey:@"Name"]; 

    return cell; 
} 

我要的是:

  1. 要改變UITableView單元的高度,所以我可以下textLabel適合更多 事情。 (目前,當我使用之前的 代碼來增加UITableView單元格的高度時,每個單元格 從不同大小的大到小)。

  2. 要在textLabel.text下顯示一個detailedTextLabel的 其他東西。

我該怎麼做?

我想:

cell.textLabel.text = [[self.jsonArray objectAtIndex:indexPath.row] objectForKey:@"Name"]; 
cell.detailTextLabel.text = [[self.jsonArray objectAtIndex:indexPath.row] objectForKey:@"Street"]; 
cell.detailTextLabel.text = [[self.jsonArray objectAtIndex:indexPath.row] objectForKey:@"City"]; 

但它不會顯示出來。

回答

0

您可以根據您的要求創建新的UItableview單元格。稍後

-(Uitableview) cellForIndexPath { 
    //add the customized Uitableviewcell. 
} 

通過這種方式,您可以按照您的要求創建tableview單元格。我希望這會有所幫助。

相關問題