开发者

different data at ech row UITableView

开发者 https://www.devze.com 2023-02-27 11:07 出处:网络
I want to know how can I display different data in 开发者_StackOverflow社区each cell of table. In my case, I have a uitable which has 4 rows. I want to display name in first row , in second row addre

I want to know how can I display different data in 开发者_StackOverflow社区each cell of table.

In my case, I have a uitable which has 4 rows. I want to display name in first row , in second row address , in third row phone no. , 4th row email . any suggestions ?

Thanks...


When you implement your tableView:cellForRowAtIndexPath: method, you can put a condition on the indexPath.row value. This is assuming that you're using the same view type for each row of the data.

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
        switch (indexPath.row) {
        case 0:
            cell.textLabel.text = /*  you data goes here */;
            break;
        case 1:
            cell.textLabel.text = /*  you data goes here */;
            break;
        /* your additional cases go here */
        }
    return cell;    
}

If you want different table view cell types for each row, you have to have different cell identifier for each one of them, and instantiate the UITableViewCell with a particular cell type that you need using a switch statement, or an if statement.


store ur data in an array suppose-arr in cellForRowAtIndexPath method write --> cell.textLable.text = [arr objectAtIndex:indexPath.row];

0

精彩评论

暂无评论...
验证码 换一张
取 消