Я следил за этим Parse Tutorial, чтобы создать пользовательский UITableViewController. Я хотел бы иметь возможность редактировать UITableView в раскадровке. Я подумал, что где-то в этом уроке я бы привязал ViewController к TableView, но у меня тоже не было. Как я могу получить доступ к этому TableView в stroyboard, который связан с этим ViewController для редактирования пользовательского интерфейса?Редактирование UITableView UITableViewController в stroryboard
Здесь находится ViewController code на GitHub.
Редактировать: Это действительно не имеет никакого отношения к API-интерфейсу. Tableview не находится в раскадровке - это проблема, которую я пытаюсь решить. Учебник поручил мне, чтобы добавить это AppDelegate.m:
MyTableViewController *controller = [[MyTableViewController alloc] init];
self.window.rootViewController = controller;
И это MyTableViewController.m:
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom the table
// The className to query on
self.className = @"Artists";
// The key of the PFObject to display in the label of the default cell style
self.keyToDisplay = @"artistName";
// Whether the built-in pull-to-refresh is enabled
self.pullToRefreshEnabled = YES;
// Whether the built-in pagination is enabled
self.paginationEnabled = YES;
// The number of objects to show per page
self.objectsPerPage = 50;
}
return self;
}
приложение работает нормально, но все, что я имею в раскадровке является пустым видом. Нужно ли создавать TableView и связывать его с MyTableViewController? Я предполагаю, что мне придется удалить этот код self.window ... из AppDelegate.
Edit: Обновлен код:
#import "MyTableViewController.h"
@implementation MyTableViewController
@synthesize tableView = _tableView;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Custom the table
// The className to query on
self.className = @"Artists";
// The key of the PFObject to display in the label of the default cell style
self.keyToDisplay = @"artistName";
// Whether the built-in pull-to-refresh is enabled
self.pullToRefreshEnabled = YES;
// Whether the built-in pagination is enabled
self.paginationEnabled = YES;
// The number of objects to show per page
self.objectsPerPage = 50;
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)viewDidUnload
{
[self setTableView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = 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 == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - Parse
- (void)objectsDidLoad:(NSError *)error {
[super objectsDidLoad:error];
// This method is called every time objects are loaded from Parse via the PFQuery
}
- (void)objectsWillLoad {
[super objectsWillLoad];
// This method is called before a PFQuery is fired to get more objects
}
// Override to customize what kind of query to perform on the class. The default is to query for
// all objects ordered by createdAt descending.
- (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:self.className];
// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if ([self.objects count] == 0) {
// ** There are other caching options in Parse iOS guide
query.cachePolicy = kPFCachePolicyNetworkElseCache;
}
[query orderByDescending:@"tweetInfluence"];
return query;
}
// Override to customize the look of a cell representing an object. The default is to display
// a UITableViewCellStyleDefault style cell with the label being the first key in the object.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Configure the cell
cell.textLabel.text = [object objectForKey:@"artistName"];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Tweet Influence: %@", [object objectForKey:@"tweetInfluence"]];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
}
@end
Спасибо, но я все еще получаю эту ошибку: 'Не удалось скомпилировать соединение: => TableCell =>>' –
mnort9
я редактировал в своем обновленном коде , Спасибо за помощь. – mnort9
Возможно, вы случайно связали ячейку со своего табличного представления как IBOutlet вместо самого представления таблицы. Попробуйте щелкнуть правой кнопкой мыши по любым видимым ячейкам просмотра таблицы и убедиться, что у них нет ничего в разделе «Outlets». Вы можете щелкнуть X, чтобы удалить их. Затем подключите таблицу к свойству 'tableView', путем ctrl-перетаскивания из некоторой области на ней, которая не покрывается ячейкой (или найдите ее в иерархии представлений в левой части экрана раскадровки). –