【发布时间】:2018-02-15 07:42:34
【问题描述】:
我在我的项目中使用 UITableView 和 2 ProtoTypeCells。我有一个主要内容的array,我想从第二个Prototypecell 即从index 1 显示。
目前我正在使用以下代码将项目隐藏在我的array 的0 index 并从array 的第一个index 开始。
有人请帮助我如何从我的 tableview 的索引 1 中显示 dataArray 的内容。
这是我的代码:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [DataArray count];
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
int feedIndex = [indexPath indexAtPosition:[indexPath length]-1];
NSLog(@"Feed Index -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- %d",feedIndex);
//Feed *item = [[[[self selectedButton] category] feedsList] objectAtIndex:feedIndex + 1];
static NSString *CellIdentifier1 = @"OneCellId";
static NSString *CellIdentifier2 = @"OtherCellId";
if(feedIndex == 0)
{
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier1] ;
[[[cell subviews] objectAtIndex:0] setTag:1];
}
UIImageView * imgvw = (UIImageView*)[cell viewWithTag:101];
imgvw.layer.cornerRadius = imgvw.frame.size.width / 2;
imgvw.clipsToBounds = YES;
imgvw.layer.borderWidth = .5f;
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:profileImg]];
imgvw.image = [UIImage imageWithData:imageData];
[self hideLoadingView];
return cell;
//cell.feed = item;
}
else
{
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier2 ] ;
[[[cell subviews] objectAtIndex:1] setTag:2];
}
NSString* OtherNameStr = [[DataArray objectAtIndex:indexPath.row]valueForKey:@"full_name"];
NSLog(@"%@",OtherNameStr);
UILabel * OtherNameLbl = (UILabel *)[cell viewWithTag:103];
OtherNameLbl.text = OtherNameStr;
这是我在 0 索引处的屏幕截图,我正在显示其他内容,从索引 1 开始,我想从 0 索引处显示 DataArray。
【问题讨论】:
-
只要输入条件 If(indexPath.row == 0){ return nil; } else{ 其余代码 }
-
试过但没用
-
您在编写
[DataArray count]-1和[DataArray objectAtIndex:indexPath.row+1]时遇到问题吗?
标签: ios objective-c uitableview nsarray