你可以用tableView數據源添加一個新類。與nesessary數據來啓動它後阿努數據換款的呼叫[的tableView的setDataSource:]:(從兩個視圖控制器使用委託合作它們。)
// DataSourceAtoZ.h
#import <Foundation/Foundation.h>
#import "MallsViewController.h"
@interface DataSourceCategory : NSObject <UITableViewDataSource> {
NSMutableArray *data;
UITableView *tableView;
}
@property (nonatomic, retain) NSMutableArray *data;
- (id)initWithData:(NSMutableArray *)d;
@end
然後,在你的代碼的任何地方,組成數據要在的tableView和設置數據源:
NSMutableArray *dt = [[NSMutableArray alloc] init];
for (int i = 0; i < [categories count]; i++) {
NSMutableArray *names = [[NSMutableArray alloc] init];
[names addObject:[[categories objectAtIndex:i] objectAtIndex:0]];
for (int j = 1; j < [[categories objectAtIndex:i] count]; j++) {
NSRange match = [[[categories objectAtIndex:i] objectAtIndex:j] rangeOfString:[params objectAtIndex:0]];
if (match.length != 0) {
[names addObject:[[categories objectAtIndex:i] objectAtIndex:j]];
}
}
[dt addObject:names];
[names release];
}
dsCategory = [[DataSourceCategory alloc] init];
dsCategory = [dsCategory initWithData:dt];
[dt release];