UITableView将数组对象放入节中

| 大家好,我需要知道是谁将这些数组对象分成两个单独的部分,这意味着一个部分用于红色单元格,另一个部分用于蓝色单元格。非常感谢您全天为您提供帮助。这是我的代码:
-(void)viewDidLoad {

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

    self.ViewTable.backgroundColor = [UIColor clearColor];    
}
    
已邀请:
        
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 2; // This returns 2 sections
}
更新:  在the2ѭ
NSInteger section = [IndexPath section];

if  (section == 0)

  // write your code for red here

if  (section == 1)

  // write your code for blue here
    
        您需要实现: 返回段数:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
返回所请求部分的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
通过读取indexPath.row和indexPath.section返回正确的单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
因此,对于红色,您将寻找一个indexPath.section等于0且indexPath.row等于0的单元格请求。蓝色将是indexPath.section等于1且indexPath.row等于0的单元格请求。     

要回复问题请先登录注册