Ios5 如何获取详细信息视图而不是表视图中的警报

Ios5 如何获取详细信息视图而不是表视图中的警报,ios5,Ios5,我想移动到名为DetailView的nib文件,而不是警报。我想不出怎样才能让它工作。我想把这一行的数据带到新的Wiew。我真的试过让它工作,但我想不出来 #import "TabBarSecondViewController.h" #import "NSDictionary+MutableDeepCopy.h" @implementation TabBarSecondViewController @synthesize names; @synthesize keys; @synthesize

我想移动到名为DetailView的nib文件,而不是警报。我想不出怎样才能让它工作。我想把这一行的数据带到新的Wiew。我真的试过让它工作,但我想不出来

#import "TabBarSecondViewController.h"
#import "NSDictionary+MutableDeepCopy.h"
@implementation TabBarSecondViewController

@synthesize names;
@synthesize keys;
@synthesize table;
@synthesize search;
@synthesize allNames;
@synthesize isSearching;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    self.title = NSLocalizedString(@"Sök Mat", @"Sök Mat");
    //self.tabBarItem.image = [UIImage imageNamed:@"second"];
}
return self;
}


#pragma mark -
#pragma mark Custom Methods
- (void)resetSearch {
self.names = [self.allNames mutableDeepCopy];
NSMutableArray *keyArray = [[NSMutableArray alloc] init];
[keyArray addObject:UITableViewIndexSearch];
[keyArray addObjectsFromArray:[[self.allNames allKeys]
                               sortedArrayUsingSelector:@selector(compare:)]];
self.keys = keyArray;
}

- (void)handleSearchForTerm:(NSString *)searchTerm {
NSMutableArray *sectionsToRemove = [[NSMutableArray alloc] init];
[self resetSearch];

for (NSString *key in self.keys) {
    NSMutableArray *array = [names valueForKey:key];
    NSMutableArray *toRemove = [[NSMutableArray alloc] init];
    for (NSString *name in array) {
        if ([name rangeOfString:searchTerm
                        options:NSCaseInsensitiveSearch].location == NSNotFound)
            [toRemove addObject:name];
    }
    if ([array count] == [toRemove count])
        [sectionsToRemove addObject:key];

    [array removeObjectsInArray:toRemove];
}
[self.keys removeObjectsInArray:sectionsToRemove];
[table reloadData];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *path = [[NSBundle mainBundle] pathForResource:@"sortednames"
                                                 ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc]
                      initWithContentsOfFile:path];
self.allNames = dict;

[self resetSearch];
[table reloadData];
[table setContentOffset:CGPointMake(0.0, 44.0) animated:NO];    

}

- (void)viewDidUnload
  {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.table = nil;
self.search = nil;
self.allNames = nil;
self.names = nil;
self.keys = nil;}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

#pragma mark -
#pragma mark Table View Data Source Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return ([keys count] > 0) ? [keys count] : 1;   
}

- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
if ([keys count] == 0)
    return 0;
NSString *key = [keys objectAtIndex:section];
NSArray *nameSection = [names objectForKey:key];
return [nameSection count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];

NSString *key = [keys objectAtIndex:section];
NSArray *nameSection = [names objectForKey:key];

static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
                         SectionsTableIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc]
            initWithStyle:UITableViewCellStyleDefault
            reuseIdentifier:SectionsTableIdentifier];
}

cell.textLabel.text = [nameSection objectAtIndex:row];
return cell;
}

- (NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section {
if ([keys count] == 0)
return nil;

 NSString *key = [keys objectAtIndex:section];
 if (key == UITableViewIndexSearch)
 return nil;
 return key;
 }
/* 
  - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
 if (isSearching)
return nil;
 return keys;
 }
 */
#pragma mark -
 #pragma mark Table View Delegate Methods
- (NSIndexPath *)tableView:(UITableView *)tableView
willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[search resignFirstResponder];
isSearching = NO;
search.text = @"";
[tableView reloadData];
return indexPath;
}

#pragma mark -
#pragma mark Search Bar Delegate Methods
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
NSString *searchTerm = [searchBar text];
[self handleSearchForTerm:searchTerm];
}

- (void)searchBar:(UISearchBar *)searchBar
textDidChange:(NSString *)searchTerm {
if ([searchTerm length] == 0) {
    [self resetSearch];
    [table reloadData];
    return;
}
[self handleSearchForTerm:searchTerm];
}

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
isSearching = NO;
search.text = @"";
[self resetSearch];
[table reloadData];
[searchBar resignFirstResponder];
}

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
isSearching = YES;
[table reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView
sectionForSectionIndexTitle:(NSString *)title
           atIndex:(NSInteger)index {
NSString *key = [keys objectAtIndex:index];
if (key == UITableViewIndexSearch) {
    [tableView setContentOffset:CGPointZero animated:NO];
    return NSNotFound;
} else return index;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath {

NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];

NSString *key = [keys objectAtIndex:section];
NSArray *nameSection = [names objectForKey:key];
NSString *selectedCell = [nameSection objectAtIndex:row];
NSLog(@"Log selectedCell: %@", selectedCell);

NSString *msg = [[NSString alloc] initWithFormat:
                 @"You have selected %@", selectedCell];
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:@"State selected"
                           message:msg
                          delegate:self
                 cancelButtonTitle:@"OK"
                 otherButtonTitles:nil];

 [alert show];        

 }


@end

您是否为DetailView的NIB创建了UIViewController?如果是,则在UIViewController中创建一对属性,以保存要推入新视图的数据。确保分配新的视图控制器,并在IB中的nib视图控制器中设置所有必要的连接和委托

然后实例化调用UIAlertView的新UIViewController

UIViewController *myVC = [[UIViewController alloc] init];
id myValueOne = [myDataOne objectAtIndex:indexPath.row];
id myValueTwo = [myDataTwo objectAtIndex:indexPath.row];
myVC.propertyOne = myValueOne;
myVC.propertyTwo = myValueTwo;
[self.navigationController pushViewController:myVC animated:YES];

希望这能有所帮助。

谢谢您的帮助。我还是没能让它工作。我有点不确定如何以及在何处声明navigationController来实现此功能。请查看UIViewController和UINavigationController的文档以获取更多信息。导航控制器是UIViewController的一个属性,在大多数情况下应该已经存在。你只要打电话就行了。再次谢谢。我正在接近:)我已经用NSLog设置了详细视图页面。当我运行时,我可以看到数据进入控制台中的详细视图,但是视图没有改变。我是否遗漏了IB中的某些内容?您是否将属性中的值设置为文本字段、文本视图等。?如果没有,您可以使用viewDidLoad或ViewDidAspect方法,将字段的文本属性设置为视图属性中的值。我只是无法让它工作,我真的被卡住了:(感谢您的努力