2013-04-05 59 views
0

我想設置一個LocalNotification,然後能夠顯示在UICollectionView上。 但是,我只知道如何使它顯示在UITable上。我應該怎麼做才能將其從UITable轉換爲UIcollectionview?我希望UIcollectionview能夠在後臺顯示帶有背景圖像的時間和日期的UIlabel。UIcollectionView上的LocalNotification顯示

這是我用本地通知構建UITable的代碼。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of notifications 
    return [[[UIApplication sharedApplication] scheduledLocalNotifications] count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
    } 
    cell.textLabel.textColor = [UIColor whiteColor]; 

    // Get list of local notifications 
    NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications]; 
    UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row]; 

    // Display notification info 
    [cell.textLabel setText:notif.alertBody]; 


    return cell; 
} 
+0

你有什麼試過的?集合視圖的API與表視圖非常相似。 – rdelmar 2013-04-05 19:10:58

回答

0

表視圖和集合視圖都使用單元格來顯示內容。一旦你有了一個集合視圖,你在這裏顯示的兩個操作(確定行數並填充一行的單元格的文本)對於集合視圖將是相同的。

按照教程得到一個集合視圖的工作,然後看看numberOfItemsInSection和cellForItemAtIndexPath:和他們比較,你有上面的方法 - 你應該能夠從的tableView使用代碼:numberOfRowsInSection:逐字,並且代碼對於其他方法只需稍作更改。

相關問題