【发布时间】:2012-04-16 12:29:46
【问题描述】:
我想向我的 customCell.m 添加一个方法,它允许我在一行中添加有关单元格的信息,所以我添加了:
-(void) addInfo:(NSString*) pTitre:(NSString*) pDescritption:(NSString*) pDate: (NSString*)pImage
{
[[self titre] setText:pTitre];
[[self description] setText:pDescritption];
[[self date] setText:pDate];
[[self couverture] setImage:[UIImage imageNamed:pImage]];
}
但是当我调用 mytableview.m 中的方法如下:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3 ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"firstviewcustomcellCell";
firstviewcustomcellCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
NSArray *topLevelObject=[[NSBundle mainBundle] loadNibNamed:@"firestViewCell" owner:nil options:nil];
for(id currentObject in topLevelObject)
{
if([currentObject isKindOfClass:[firstviewcustomcellCell class]])
{
cell=(firstviewcustomcellCell*) currentObject;
break;
}
}
}
[cell addInfo:
@"journal 1":
@"description 1":
@"01/02/2012":
@"second.png"];
[cell addInfo:
@"journal 2":
@"description 2":
@"01/02/2012":
@"second.png"];
return cell;
}
这是它显示的内容:
http://img213.imageshack.us/img213/2346/capturedcran20120416142.png
感谢您的宝贵时间
【问题讨论】:
-
第二次调用
addInfo不是覆盖了第一次调用吗? -
不应该是不同的单元格吗?
-
正如@Nit 已经指出的那样,您需要某种 logic 来确定用什么填充单元格 - 您总是对所有单元格做同样的事情,因此你看到的结果。
-
@Hosni 访问 Apple 开发者网站并阅读他们关于模型视图控制器的文档并查看 UITableView 的示例代码。如果你继续你正在做的事情,即使你得到了这个工作(使用下面的答案),那么你将来会让自己的事情变得更加困难。当前的答案集仅显示如何获得您当前的工作。他们没有展示正确的做法
标签: iphone objective-c class customization