2011-06-01 14 views
0

使用UITableview顯示來自TouchXML的NSDictionary的數據。 TouchXML是一個在我的iPhone應用程序中集成XML提要的系統。viewForItemAtIndex中的對象

對於泰伯維這一切的作品,我把的NSDictionary這樣在我的UITableView:

[[[newsEntries objectAtIndex:indexPath.row] objectForKey: @"still"] retain]; 

我現在用的iCarousel軟件,它的一個開源的CoverFlow類似系統。在我使用AFOpenFlowView之前,這只是一個痛苦,因爲它不會接受UIViews。只有圖像。

我需要從XML中加載iCarousel中的縮略圖。所以我需要從字典中獲取一個字符串並將其更改爲UIImage。

我做了這項工作。我遇到的問題是我需要在iCarousel中加載多個圖像,就像在TableView行中加載多個圖像/縮略圖一樣。 現在我需要對iCarousel做同樣的事情,但是如何?

這是我目前的收費情況。問題是一個TableView有一個indexPath.row,而這個viewForItemAtIndex沒有。

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index { 
    //create a numbered view 
    NSString *imageUrl = [[[newsEntries objectAtIndex:indexPath.row] objectForKey:@"still"] retain]; 
    NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imageUrl]]; 
    UIView *view = [[[UIImageView alloc] initWithData:imageData] autorelease]; 
    UILabel *label = [[[UILabel alloc] initWithFrame:view.bounds] autorelease]; 
    label.text = [NSString stringWithFormat:@"%i", [[items objectAtIndex:index] intValue]]; 
    label.backgroundColor = [UIColor clearColor]; 
    label.textAlignment = UITextAlignmentCenter; 
    label.font = [label.font fontWithSize:50]; 
    [view addSubview:label]; 
    return view; 
} 

回答

1

不宜與index工作更換indexPath.row

NSString *imageUrl = [[[newsEntries objectAtIndex:index] objectForKey:@"still"] retain]; 
+1

然後我得到一個指數超越界限1 ... 19 – ruben 2011-06-01 09:36:23

+1

如果索引是一次性的,那麼你總是可以減去一個像'objectAtIndex:(index - 1)'。 – 2011-06-01 09:38:17

+0

你對'numberOfItemsInCarousel:'返回什麼? – 2011-06-01 09:46:02

0
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel 
{ 
    return [items count]; 
} 
0

這是響應當我登錄與對象的字符串鍵

2011-06-01 14:57:51.273 [711:207] my url = (null) 
2011-06-01 14:57:51.277 [711:207] my url = (null) 

等等,等等等等