-1
我正在使用帶有SWRevealView控制器的Fitness(鍛鍊)調度程序應用程序,該應用程序提供側欄菜單功能。UITableViewCell不顯示陣列中的內容
我試圖將一個單元格從側欄菜單鏈接到另一個Tableview控制器,在那裏我設置了它們之間的連線。
segue很好,但它不顯示我在可變數組中的文本數據。
MainViewController.h
#import <UIKit/UIKit.h>
@interface MainViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton;
@end
MainViewController.m
#import "MainViewController.h"
#import "SWRevealViewController.h"
@interface MainViewController()
@property (nonatomic) NSMutableArray *plans;
@property (nonatomic) NSArray *categories;
@end
@implementation MainViewController
- (void)viewDidLoad {
[super viewDidLoad];
// [UITableView setDelegate:self];
// [UITableView setDataSource:self];
self.plans = @[@{@"name" : @"Week 1-3", @"category" : @"Buff Dudes Workout"}, @{@"name" : @"Week 4-6", @"category" : @"Buff Dudes Workout"}, @{@"name" : @"Week 7-9", @"category" : @"Buff Dudes Workout"}, @{@"name" : @"Week 10-12", @"category" : @"Buff Dudes Workout"}].mutableCopy;
self.categories = @[@"Buff Dudes Workout"];
self.title = @"Workout Programs";
SWRevealViewController *revealViewController = self.revealViewController;
if (revealViewController)
{
[self.sidebarButton setTarget: self.revealViewController];
[self.sidebarButton setAction: @selector(revealToggle:)];
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - DataSource helper methods
- (NSArray *) itemsInCategory:(NSString *)targetCategory {
NSPredicate *matchingPredicate = [NSPredicate predicateWithFormat:@"category == %@", targetCategory];
NSArray *categoryItems = [self.plans filteredArrayUsingPredicate:matchingPredicate];
return categoryItems;
}
- (NSInteger)numberOfItemsInCategory:(NSString *)targetCategory {
return [self itemsInCategory:targetCategory].count;
}
- (NSDictionary *)itemAtIndexPath:(NSIndexPath *)indexPath {
NSString *category = self.categories[indexPath.section];
NSArray *categoryItems = [self itemsInCategory:category];
NSDictionary *item = categoryItems[indexPath.row];
return item;
}
- (NSInteger)itemIndexForIndexPath:(NSIndexPath *)indexPath {
NSDictionary *item = [self itemAtIndexPath:indexPath];
NSInteger index = [self.plans indexOfObjectIdenticalTo:item];
return index;
}
//- (void)removeitemsAtindexPath:(NSIndexPath *)indexPath {
// NSInteger index = [self itemIndexForIndexPath:indexPath];
// [self.items removeObjectAtIndex:index];
#pragma mark - table view datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return self.categories.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self numberOfItemsInCategory:self.categories[section]];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"workoutplanrow";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSDictionary *plans = [self itemAtIndexPath:indexPath];
cell.textLabel.text = plans[@"name"];
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return self.categories[section];
}
@end
我覺得有什麼不對,我ellForRowAtIndexPath method
。
檢查你的nsmutable在使用前是否正確分配了 – Lorenzo
爲什麼'setDelegate'和'setDataSource'被註釋掉? – ozgur
嘗試'NSLog(@「cell.textLabel.text%@」,cell.textLabel.text);'設置文本後'cell.textLabel.text = plans [@「name」];'。它實際上有價值嗎?或者它是空的? – SFF