試圖實現一個「簡單」一個CustomCell, 我有一個正常的tableViewController,使用正常的「默認」方法,但我需要實現一個自定義單元格與一些UILabel和UIImage罰款。Iphone UITableViewCell CustomCell
因此,我創建了CustomCell.h,CustomCell.m,CustomCell.xib
的.H
@interface CustomCell : UITableViewCell <UITextViewDelegate>
{
IBOutlet UIImageView *image;
IBOutlet UILabel *name;
IBOutlet UILabel *date;
IBOutlet UILabel *comment;
}
@property (retain,nonatomic) IBOutlet UIImageView *image;
@property (retain,nonatomic) IBOutlet UILabel *name;
@property (retain,nonatomic) IBOutlet UILabel *date;
@property (retain,nonatomic) IBOutlet UILabel *comment;
和.M
@implementation CustomCell
@synthesize image;
@synthesize name;
@synthesize date;
@synthesize comment;
#pragma mark -
#pragma mark View lifecycle
- (id) initWithController: (Controller *) ctnlr
{
ControllerPointer = ctnlr;
return(self);
}
- (void) SetImage:(UIImageView*)Image
{
image = Image;
}
- (void) SetName:(NSString*)Name
{
[Name retain];
[name.text release];
name.text = Name;
}
- (void) SetDate:(NSString*)Date
{
[Date retain];
[date.text release];
date.text = Date;
}
- (void) SetComment:(NSString*)Comment
{
[Comment retain];
[comment.text release];
comment.text = Comment;
}
反正,當我嘗試創建cellForRowAtIndexPath中的這些自定義單元(正如我們期望的那樣可能會實現),我只剩下一個空白屏幕。所以很顯然我缺少一些大的東西......當我用「Interface Builder」創建.XIB文件時,我確保將「引用插座」連接到適當的標籤和圖像。
這樣的Xcode的框架出現的工作方式隱含邏輯下, 我遵循同樣的理由(因爲缺乏一個確切的例子)沒有worky ... 無論如何,如果有任何IPhone怪才,就是想來開導我... (是的,沒有「[釋放]」的電話,我甚至不知道是否需要分配任何東西,請告訴我只有幾個電話我要離開,它可以「T比簡單的東西像這樣的權太大更多...?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil] lastObject];
}
NSUInteger row = [indexPath row];
SnsObject *sObj = [SnsArray objectAtIndex:row];
[cell SetName:[sObj getUserName]];
NSUInteger row = [indexPath row];
SnsObject *sObj = [SnsArray objectAtIndex:row];
cell.name = [[UILabel alloc]init];
cell.name.text = [sObj getUserName];
cell.date = [[UILabel alloc]init];
cell.date.text = [sObj getDateTime];
cell.comment = [[UILabel alloc]init];
cell.comment.text = [sObj getCommentText];
cell.image = [[UIImageView alloc]init];
cell.image.image = [sObj getImageUrl];
return(cell)
}
提前感謝!
好吧......有點困惑你在做什麼,但確定...所以不是在tableViewController類的標題引用了我的「CustomCell * customCell」的,我要引用通用「的UITableViewCell * tvCell「...確定....就我的」CustomCell.m&.h「他們不會改變...?並在「TableViewController.m」cellForRowAtIndexPath()我有點失去了我究竟會創造什麼......?以及我的「CustomCell」如何被實例化,如果它甚至沒有被引用......請賜教我......先謝謝了! – chinasailor 2011-02-09 01:47:53