好吧,我知道我的 n00b-ness 会惹恼这里的某个人,所以认为这是一个公平的警告。我对 Obj-C 来说是新鲜的,所以对你来说很明显的东西对我来说很可能不会。
我一直在关注TableViewControllers 上的本教程,但我一辈子都无法让单元格标题出现。我已经将网站上的每一行代码都删掉了,并调试了一个 SIGABRT 错误,但即使现在数据也没有出现。
下面分别是 MasterViewController.h 和 /.m 文件的内容:
头文件:
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import <UIKit/UIKit.h>
@class DetailViewController;
@interface MasterViewController : UITableViewController <NSFetchedResultsControllerDelegate, UITableViewDelegate, UITableViewDataSource>
@property (strong, nonatomic) DetailViewController *detailViewController;
// Create property "equations" as an instance of NSArray:
@property (strong, nonatomic) NSMutableArray *equations;
@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@end
实现文件:
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "MasterViewController.h"
#import "DetailViewController.h"
@interface MasterViewController ()
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;
@end
@implementation MasterViewController
// Synthesize NSArray instance for equation storage:
@synthesize equations = _equations;
// Segue linking as per DetailViewController.h/.m:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
DetailViewController *destViewController = segue.destinationViewController;
destViewController.equationName = [_equations objectAtIndex:indexPath.row];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
self.title = @"Equations";
if (!_equations)
{
_equations = [[NSMutableArray alloc] initWithObjects:
// Atomic structure equations:
@"Energy-Frequency Relation",
@"Energy-Frequency-Wavelength Relation",
@"Energy-Quantum Number Relation",
@"Momentum-Mass-Frequency",
@"Speed of Light Definition",
// Equilibrium equations:
@"Equilibrium Acid Constant",
@"Equilibrium Base Constant",
@"Water Equilibrium Constant",
@"pH Calculation",
@"pH-Acid Constant Relation",
@"pOH-Base Constant Relation",
@"pKa Derivation",
@"pKb Derivation",
@"pOH Calculation",
@"Gas-pressure Equlibrium",
// Gas/solution chemistry equations:
@"Ideal-Gas Law",
@"Partial-pressure equation",
@"Total pressure (3 partials)",
@"mol-Molarity Calculation",
@"Kelvin-Celsius Relation",
@"Fahrenheit-Celsius Relation",
@"Density Calculation",
@"Kinetic Energy per Molecule",
@"Kinetic Energy per Mol",
@"Molarity Equation",
@"Molality Equation",
@"Absorbance Equation",
@"Freezing Point Depression",
@"Boiling Point Elevation"
// Redox Equations:
@"Electrical current definition",
@"Equilibrium vs. Reduction Potential",
// Thermochemical relations:
@"Change in Free Energy",
@"Molar Heat Capacity",
@"Frequency to Rate Factor",
nil];
}
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return call from NSArray *equations as to the count of elements in the table view:
return [_equations count];
}
- (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
UILabel *lblName = (UILabel *)[cell viewWithTag:100];
[lblName setText:[_equations objectAtIndex:[indexPath row]]];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return NO;
}
我省去了你们所有的 250 行代码,只删掉了似乎与视图控制器本身有关的部分。有些事情告诉我,我只是省略了必要的连接代码行,但是我对语言的完整介绍状态以及缺少调试器错误并没有让我感到困惑。有任何想法吗?任何帮助(不包括挑剔)都值得赞赏和欢迎。