iphone - UITableview - headerview не загружает объектные клавиши - PullRequest
1 голос
/ 09 ноября 2010

У меня есть табличное представление с добавленным заголовком, созданным в IB для отображения некоторого текста над таблицей (не удалось опубликовать снимок экрана - http://i51.tinypic.com/2przbl5.jpg).. Я хочу загрузить текст над таблицей на основе моегоplist и я использую objectforkey для загрузки текста. Однако, когда я соединяю выходы в IB, текст исчезает. Это работало в стандартном UIview, поэтому я не уверен, что мне не хватает в табличном представлении. Я новичок втак что, возможно, есть лучший способ сделать это или что я делаю не так? спасибо.

.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

Ответы [ 2 ]

0 голосов
/ 09 ноября 2010

Обычно, когда вы используете UITableViewController, текст, подобный тому, который вы пытаетесь отобразить, должен идти в заголовке таблицы.Вот как вы можете добавить метку к заголовку таблицы:

UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,300,100)];
UILabel *header = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 50)];
[header setTextColor:[UIColor redColor]];
[header setText:@"Some Text"];
[headerView addSubview:header];

[self.tableView setTableHeaderView:headerView];
0 голосов
/ 09 ноября 2010

Я не уверен, что понимаю ваш вопрос, но вы могли бы создать 2 списка, точки и тур, а затем заполнить массив и словарь Mutable содержимым списка.

EDIT ****************************

Я пропустил это раньше, но, может быть, это так же просто, как добавить @ "", например

[tour objectForKey:@"NAME_KEY"];

Вы должны сделать ваш массив и словарь изменяемыми, если вы хотите изменить данные внутри них по любой причине.

Вот так код для получения plist и заполнения вашего массива или словаря (не забудьте установить plists на соответствующий тип при заполнении их)

Поместите это в ваш метод viewDidLoad

NSString *pointsList = [[NSBundle mainBundle] 
  pathForResource:@"points" ofType:@"plist"];
  points = [[NSMutableArray alloc]initWithContentsOfFile: pointsList];

NSString *tourList = [[NSBundle mainBundle] 
  pathForResource:@"tour" ofType:@"plist"];
  tour = [[NSMutableArray alloc]initWithContentsOfFile: tourList];

Тогда ваш массив и словарь заполнены содержимым plist.

Надеюсь, это поможет, может быть, я неправильно понял, что вы хотите сделать.

...