私は初心者なので、ストーリーボードでXcode 4.3.2を使用しているので、コードの知識はあまりよくありません。これまで、データを含むテーブルビューにリンクするメインビューコントローラーによって作成しました。ただし、これを新しいView Controllerにリンクする方法がわかりません。つまり、新しいView Controllerをストーリーボードページにドラッグした場合、テーブルビューのセルを選択して、詳細を含む新しいページを開きます。チュートリアルの助けを借りたこれまでの私のコードは次のとおりです:-
Viewcontroller.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITabBarDelegate, UITableViewDataSource, UISearchBarDelegate>
{
IBOutlet UITableView * tableView;
IBOutlet UISearchBar * searchBar;
NSArray * allItems;
NSMutableArray * displayItems;
}
@end
Viewcontroller.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
allItems = [[NSArray alloc] initWithObjects:@"K12", @"K14", @"K16", @"K18", @"K42", @"K43", @"K46", @"K53", @"K60", @"K68", @"K81", @"K83", nil];
displayItems = [[NSMutableArray alloc] initWithArray:allItems];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [displayItems count];
}
- (UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
cell.textLabel.text = [displayItems objectAtIndex:indexPath.row];
return cell;
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
if ([searchText length] == 0) {
[displayItems removeAllObjects];
[displayItems addObjectsFromArray:allItems];
} else {
//here
[displayItems removeAllObjects];
for (NSString * string in allItems) {
NSRange r = [string rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (r.location != NSNotFound) {
[displayItems addObject:string];
}
}
}
[tableView reloadData];
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)aSearchBar {
[searchBar resignFirstResponder];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
私はアプリの残りの部分をこのビットに固執し、さまざまなコードを調べたチュートリアルを検索して快適に作業できますが、私の知識は非常に限られているため、ダミーガイドが必要です。素晴らしい。
みんなに感謝し、助けていただければ幸いです。