有一個想法來解決這個問題?問題cellForRowAtIndexPath和NSBundle mainBundle
這是respectly的正確和錯誤的方法:
這是工作代碼:
- (UITableViewCell *)[...] cellForRowAtIndexPath:(NSIndexPath *)indexPath {
@try {
newsRow = ((NewsRowController *)[tableView dequeueReusableCellWithIdentifier:@"cell"]);
if (newsRow == nil) {
if ([[Device GetModel] isEqualToString:@"iPad Simulator"] ||
[[Device GetModel] isEqualToString:@"iPad"])
[[NSBundle mainBundle] loadNibNamed:@"NewsRow_ipad" owner:self options:nil];
else [[NSBundle mainBundle] loadNibNamed:@"NewsRow" owner:self options:nil];
if ([tableArray count] > 0)
[newsRow setData:[tableArray objectAtIndex:indexPath.row]];
}
}
@catch (NSException * e) {
NSLog(@"a!!!!!");
}
return newsRow;
}
...但因爲在我的3G手機是慢慢當我滾動表上/下我改變了這種方式的代碼,插入設備檢查viewDidLoad並通過它在cellForRowAtIndexPath
:
NSArray *cRow;
@property (nonatomic, retain) NSArray *cRow;
[...]
@syntetize cRow;
- (void)viewDidLoad {
[...]
if ([[Device GetModel] isEqualToString:@"iPad Simulator"]
||
[[Device GetModel] isEqualToString:@"iPad"])
cRow = [[[NSBundle mainBundle] loadNibNamed:@"NewsRow_ipad" owner:self options:nil] retain];
else cRow = [[[NSBundle mainBundle] loadNibNamed:@"NewsRow" owner:self options:nil] retain];
[...]
}
- (UITableViewCell *)[...] cellForRowAtIndexPath:(NSIndexPath *)indexPath {
@try {
newsRow = ((NewsRowController *)[tableView dequeueReusableCellWithIdentifier:@"cell"]);
if (newsRow == nil) {
//
// ADDED CODE.
//
newsRow = [cRow objectAtIndex:0];
//
if ([tableArray count] > 0)
[newsRow setData:[tableArray objectAtIndex:indexPath.row]];
}
}
@catch (NSException * e) {
NSLog(@"a!!!!!");
}
return newsRow;
}
現在表格只顯示一行。如果我滾動,行更改,但它只顯示一行...
有什麼問題?
有幫助嗎?
感謝,
一個
好的,我該如何解決問題? – elp
您可以開始將加載筆尖的代碼移回tableView:cellForRowAtIndexPath :,如果您在iPad上沒有使用viewDidLoad,則可以存儲BOOL。如果在此之後滾動仍然很慢,而不是在nib中創建的單元格,則可以像Apple那樣在您的示例中創建您自己的UITableViewCell的子類。 – criscokid
完美。有沒有辦法在一個var中設置[[NSBundle mainBundle] loa ...]來在循環中使用? – elp