-3

ねえ、私はこれらの配列オブジェクトを2つの別々のセクションに配置する人を知る必要があります。つまり、1つのセクションは赤いセル用で、もう1つのセクションは青いセル用です。あなたの助けが今一日中これに固執していることを本当に感謝します。これが私のコードです:

-(void)viewDidLoad {

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

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

2 に答える 2

2

以下を実装する必要があります。

セクション数を返す:

- (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 です。

于 2011-06-23T19:16:42.923 に答える
1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 2; // This returns 2 sections
}

更新 :cellForRowAtIndexPath

NSInteger section = [IndexPath section];

if  (section == 0)

  // write your code for red here

if  (section == 1)

  // write your code for blue here
于 2011-06-23T19:10:06.907 に答える