开发者

Display results in two columns

开发者 https://www.devze.com 2023-03-17 09:38 出处:网络
I have an array that has three properties Image Name Date I would like to display this in two columns instead of in a table view which only gives me one column. How can I do this?

I have an array that has three properties Image Name Date

I would like to display this in two columns instead of in a table view which only gives me one column. How can I do this?

Than开发者_C百科ks,


Subclass UITableViewCell - e.g. MyUITableViewCell, then add two UILables to your new cell. Place them as you wish (e.g. each half the cell's width, one aligning left, one aligning right).

Then your cellForRowAtIndexPath method in the UITableView's dataSource, instead of creating a new instance of UITableViewCell, create an instance of MyUITableViewCell and set the two UILables' texts to the data you want to display.


If you want to use interface builder, you can just layout the views you want inside a UITableViewCell, tag them with different numbers and then use something like this:

- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier {

    NSArray* nibViews =  [[NSBundle mainBundle] loadNibNamed:@"TableCells" owner:self options:nil];
    UITableViewCell *cell = [nibViews objectAtIndex:1];

    return cell;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [self getCellContentView:CellIdentifier];
    }

    Account *acc = [accountManager.accounts objectAtIndex:indexPath.row];
    UILabel *title = (UILabel*)[cell viewWithTag:1];
    UILabel *counters = (UILabel*)[cell viewWithTag:3];

    title.text = acc.title;
    counters.text = [acc statusText];

    return cell;
}


You have only rows and sections in iPhone development. If you need columns, you should add the image, name and date as subviews to your UITableViewCell

UITableViewCell *cell ; //  allocate this
[cell addSubview: comboView]; // where comboView has 3 views in it.  
0

精彩评论

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

关注公众号