我有我正在項目,我需要添加搜索到我的uitableview
。我一直在看很多代碼,但大多數他們不是我正在尋找,我不能修改它們。有人可以幫我添加搜索到我的tableview
。我也想推detailview
從searcharray
。先謝謝你。添加搜索NSMutable陣列與DetailView
這裏是.H uitableview
#import <UIKit/UIKit.h>
@interface Reds : UITableViewController {
NSMutableArray *dummyArray;
}
- (void) setupData;
@end
這裏.M uitableview
#import "Reds.h"
#import "RedsDetail.h"
@interface Reds()
@end
@implementation Reds
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupData];
}
- (void) setupData {
dummyArray = [[NSMutableArray alloc] init];
[dummyArray addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"dummy 1", @"name" , @"image1.JPG", @"image" , @"dummy 1 description textview", @"description", nil]];
[dummyArray addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"dummy 2", @"name" , @"image1.JPG", @"image" , @"dummy 2 description textview", @"description", nil]];
[dummyArray addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"dummy 3", @"name" , @"image1.JPG", @"image" , @"dummy 3 description textview", @"description", nil]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [dummyArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [[dummyArray objectAtIndex:indexPath.row] objectForKey:@"name"];
return cell;
}
#pragma mark - Table view delegate
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"DummyDetail"]){
RedsDetail *dummyDetail = [segue destinationViewController];
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
dummyDetail.dummyImageString = [[NSString alloc] initWithString:[[dummyArray objectAtIndex:indexPath.row] objectForKey:@"image"]];
dummyDetail.dummyTextString = [[NSString alloc] initWithString:[[dummyArray objectAtIndex:indexPath.row] objectForKey:@"description"]];
dummyDetail.title = [[NSString alloc] initWithString:[[dummyArray objectAtIndex:indexPath.row] objectForKey:@"name"]];
}
}
@end
這裏是.H detailview
#import <UIKit/UIKit.h>
@interface RedsDetail : UIViewController {
IBOutlet UIImageView *dummyImage;
IBOutlet UITextView *dummyText;
NSString *dummyImageString;
NSString *dummyTextString;
}
@property (nonatomic, retain) NSString *dummyImageString;
@property (nonatomic, retain) NSString *dummyTextString;
@end
終於.M detailview
#import "RedsDetail.h"
@interface RedsDetail()
@end
@implementation RedsDetail
@synthesize dummyImageString, dummyTextString;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
dummyImage.image = [UIImage imageNamed:dummyImageString];
dummyText.text = dummyTextString;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
我知道這對大多數人來說可能是一個簡單的答案,但我無法弄清楚,我需要幫助。我真的很感謝你們花時間幫助我。我也使用xcode 4.5 ios 6故事板,如果這使你的答案有所不同。
阿德里安
我認爲這篇文章將引領你在正確的方向:HTTP://計算器。com/questions/2609958/how-to-search-through-a-nsmutablearray –
感謝大衛,但我一直在尋找代碼片段的幫助。我已經通過文檔,但我很難做到這一點,而無需改變我的班級結構。我正試圖避免這種情況。但是如果我不能得到任何幫助,我可能必須:( –
其他人都在意幫忙嗎? –