0

次のように表示されているNSMutableArrayがあります

 (
          13002,
          My Drive,
          13006,
          Testing1,
          13007,
          Testing123    
 )

私のNSLogで

UITableViewに名前(My Drive、Testing1、Testing123)だけを入力し、IDをサブタイトルとして使用したいと思います。

4

4 に答える 4

0
NSmutableArray *element; //contains your array

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

    static NSString *cellIdentifier = @"MyCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];

    element = [array objectAtIndex:indexPath.row];
    cell.textLabel.text = element;


    element = [array objectAtIndex:indexPath.row +1 ];
    cell.subtitle.text = element; 
于 2013-03-25T10:08:12.063 に答える
0

以下のように、インデックスパスメソッドと行数メソッドで行にセルを使用します

 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
        return array.count/2;
 }


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      int row = [indexPath row]*2;

      static NSString *CellIdentifier = @"Cell";

      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil) {
              cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
              cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
              cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
     }    

     cell.textLabel.text = [array objectAtIndex:row+1];
     cell.detailTextLabel.text = [array objectAtIndex:row];

     return cell;
}

あなたの問題は解決します...

于 2013-03-25T10:09:45.710 に答える
0

アプリケーションによっては、アレイの代わりにNSMutableDictionaryの使用を検討することをお勧めします。このように、データモデルは、これらの名前がIDにマップされているという事実を正確に表します。使用できます

NSArray *arrayOf Keys = [theDictionary allKeys];

辞書のキーの配列を取得するには、次のようにします。

cell.textLabel.text = [theDictionary objectForKey:[arrayOfKeys objectAtIndex:indexPath.row]];
cell.detailtextLabel.text = [arrayOfKeys objectAtIndex:indexPath.row];
于 2013-03-25T10:22:31.217 に答える
0

また、無料のSensibleTableViewフレームワークの使用を検討する必要があります。配列をフレームワークに渡すだけで、テーブルビューに自動的に表示されます。

于 2013-03-25T19:08:17.400 に答える