好的,所以我尝试了很多不同的方法......
目前我已经把UINavigationBar
IB 放在了一起。然后用IBOutlet
.
无论我尝试什么,从那里我似乎都无法更改标题。即使只是在ViewDidLoad
.
另外,我不需要分配导航栏的代表吗?
这是我的代码:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController < UITableViewDataSource, UITableViewDelegate>
{
NSArray *myArrayOne;
NSArray *myArrayTwo;
UITextView *myTextView;
UINavigationBar *myNavBar;
}
@property (nonatomic, retain) NSArray *myArrayOne;
@property (nonatomic, retain) NSArray *myArrayTwo;
@property (nonatomic, retain) IBOutlet UITextView *myTextView;
@property (nonatomic, retain) IBOutlet UINavigationBar *myNavBar;
@end
和:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
//Synthesising anything with a property call in the .h file.
@synthesize myArrayOne;
@synthesize myArrayTwo;
@synthesize myTextView;
@synthesize myNavBar;
- (void)viewDidLoad
{
//declaring and instantiating datapaths and also
// reading into arrays from plist.
NSString *datapath1 = [[NSBundle mainBundle] pathForResource:@"myListOne" ofType:@"plist"];
NSString *datapath2 = [[NSBundle mainBundle] pathForResource:@"myListTwo" ofType:@"plist"];
myArrayOne = [[NSArray alloc] initWithContentsOfFile:datapath1];
myArrayTwo = [[NSArray alloc] initWithContentsOfFile:datapath2];
self.navigationItem.title = @"Hi";
[super viewDidLoad];
}
#pragma mark - TableView Delegate stuff
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//myNavBar.title = [myArrayOne objectAtIndex:indexPath.row];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark - TableView Datasource stuff
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//returns amount of items inside myArrayOne as amount of rows
return [myArrayOne count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *myCell = nil;
myCell = [tableView dequeueReusableCellWithIdentifier:@"myReuseCell"];
if (myCell == nil)
{
myCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"myReuseCell"];
}
myCell.textLabel.text = [myArrayOne objectAtIndex:indexPath.row];
return myCell;
}
@end
更改标题的实际代码只是我尝试过的一种方法......
还有什么办法吗?我需要将 IB 中的导航栏与任何东西链接吗?