Cyril
Cyril

Reputation: 1236

How to Create a Table like the below

I have created a TableView(Grouped Table View). And I can list the items in the table view. But I want to know how the below table is displayedenter image description here

Like Calender is in the left side, and Gregorian in the Right Side ?? How that Gregorian is displayed in the Right Side ?? Is it a Custom TableView, Can anyone help me how to achieve that ?

Upvotes: 3

Views: 1770

Answers (3)

Nimit Parekh
Nimit Parekh

Reputation: 16864

You need to use following code helping to you

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        UIImageView *v = [[[UIImageView alloc] init]autorelease];
        v.backgroundColor = [UIColor clearColor]; // put clear color
        [v setClipsToBounds:YES];
        cell.selectedBackgroundView = v;
        [cell setClipsToBounds:YES];
    }
    UIImageView *imgVBG=(UIImageView*)[cell selectedBackgroundView];
    if(indexPath.row==0){
        imgVBG.image=[UIImage imageNamed:@"TopImg.png"];
    } else if((indexPath.section==0 && indexPath.row==4)||(indexPath.section==1 && indexPath.row==7)){
        imgVBG.image=[UIImage imageNamed:@"BottomImg.png"];
    } else {
        imgVBG.image=[UIImage imageNamed:@"MiddleImg.png"];
    }
}

Upvotes: 1

yuji
yuji

Reputation: 16725

Those are just regular cells with style = UITableViewCellStyleValue1 and also accessoryType = UITableViewCellAccessoryDisclosureIndicator.

To make one programmatically:

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"YourIdentifier"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

(Note that in real life you would probably try to dequeueReusableCellWithIdentifier:, and only create a new cell if that returns nil.)

Or, if you're working with IB, set "Style" to "Right Detail" and "Accessory" to "Disclosure Indicator".

Upvotes: 10

Related Questions