我有一个表视图,与IB创建添加headerview显示在表上方的一些文本(无法发布截图-http://i51.tinypic.com/2przbl5.jpg)。我想根据我的plist加载表格上方的文本,并使用objectforkey加载文本。但是,当我连接IB中的插座时,文字消失。这工作在一个标准的UIview,所以我不知道我在表视图中缺少什么。我是新来的编码,所以也许有更好的方法来做到这一点,或者我做错了什么?谢谢。iphone - UITableview - headerview不加载objectkey
.h file _________________________________________________
#import <UIKit/UIKit.h>
@interface TourOverviewController : UITableViewController {
NSArray *points;
NSDictionary *tour;
IBOutlet UITextField *nameTextField;
IBOutlet UITextView *pointsTextView;
}
@property (nonatomic, retain) NSArray *points;
@property (nonatomic, retain) NSDictionary *tour;
@property (nonatomic, retain) UITextField *nameTextField;
@property (nonatomic, retain) UITextView *pointsTextView;
@end
.m file______________________________________________________
#import "TourOverviewController.h"
#import "LoadingNames.h"
@implementation TourOverviewController
@synthesize points, tour, nameTextField, pointsTextView,
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
nameTextField.text = [tour objectForKey:NAME_KEY];
pointsTextView.text = [tour objectForKey:DIRECTIONS_KEY];
}
- (void)viewDidLoad {
NSArray *array = [[NSArray alloc] initWithObjects:@"Toy Story",
@"A Bug's Life", @"Toy Story 2", @"Monsters, Inc.",
@"Finding Nemo", @"The Incredibles", @"Cars",
@"Ratatouille", @"WALL-E", nil];
self.points = array;
[array release];
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [points count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
NSString *rowString = [points objectAtIndex:row];
cell.textLabel.text = rowString;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
[rowString release];
return cell;
}
@end
谢谢,我在我的rootcontoller有类似的东西。当我添加它时,它会运行并获得相同的结果。当我把相同的项目从tableheader中拿出来,并且在UIview中,所有的东西都连接好了......所以我想它与表格标题中的某些东西有关。 – alittlelost 2010-11-09 13:55:44
这应该可以解决您的问题。 :) http://www.purplehazeapps.com/home/index.php?option=com_content&view=article&id=84:headerfooterinuitableview&catid=37:myblog&Itemid=171 – jarryd 2010-11-09 21:16:45
感谢所有帮助你们!我只是想通了,当我从我的根控制器中推出页面时,我不小心删除了plist文件中的行。是的,它终于工作=) – alittlelost 2010-11-10 16:41:12