开发者

UITableView Putting array objects into sections

开发者 https://www.devze.com 2023-03-14 20:47 出处:网络
Hey guys I need to know who to put these array objects into two separate sections, that means 开发者_开发问答one section for the red cell and another section for the blue cell. Would really appreciate

Hey guys I need to know who to put these array objects into two separate sections, that means 开发者_开发问答one section for the red cell and another section for the blue cell. Would really appreciate your help been stuck on this all day now. Here is my code:

-(void)viewDidLoad {

    [super viewDidLoad];
    //Initialize the array.
    array = [[NSMutableArray alloc] init];
    [array addObject:@"Red"];
    [array addObject:@"Blue"];

    self.ViewTable.backgroundColor = [UIColor clearColor];    
}


You need to implement:

return number of sections:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

return number of rows for the requested section

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

return correct cell by reading both indexPath.row and indexPath.section

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

So for red you would look for a cell request that has indexPath.section equal to 0 and indexPath.row equal to 0. blue would be indexPath.section equal to 1 and indexPath.row equal to 0


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 2; // This returns 2 sections
}

Updated: In the cellForRowAtIndexPath

NSInteger section = [IndexPath section];

if  (section == 0)

  // write your code for red here

if  (section == 1)

  // write your code for blue here
0

精彩评论

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