Tuesday, December 24, 2013

About UITableViewController cause the program to exit

I wrote a subclass inherits from UITableViewController, one function will cause the program to hang a start. I commented that function to the program would not be wrong, that function is:
 
- (NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section
{
return [[masterColorList objectAtIndex: section] count];
}

Reply:
[MasterColorList objectAtIndex: section]
section should not exceed the masterColorList the count,
To be tested.
There is a function, numberOfSections your return is.
Reply:
Ask the landlord how to get the section of how much???? Put this issue is resolved behind easier, there is little, when loading content TableView of your masterColorList not because the other operations!
Reply:
[MasterColorList objectAtIndex: section] to be printed out on

Reply:
As long as I have - (NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section of this function is to comment out the program would not be wrong, but there is no data show.
Reply:
I put the code stickers, heroes who helped look ah, just started learning, and consequently will not ah, thank.

Headers
 
# Import


@ Interface RootViewController: UITableViewController
{
NSArray * masterColorList;
}

@ Property (retain) NSArray * masterColorList;
@ End



Code files:
 
# Import "RootViewController.h"
# Import "CoreGraphics / CGGeometry.h"


@ Implementation RootViewController
@ Synthesize masterColorList;

- (Id) initWithCoder: (NSCoder *) decoder
{
if (self = [super initWithCoder: decoder])
{

NSArray * colorList = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys: @ "brownColor", @ "titleValue", [UIColor brownColor], @ "colorValue", nil],
[NSDictionary dictionaryWithObjectsAndKeys: @ "orangeColor", @ "titleValue", [UIColor orangeColor], @ "colorValue", nil],
[NSDictionary dictionaryWithObjectsAndKeys: @ "purpleColor", @ "titleValue", [UIColor purpleColor], @ "colorValue", nil],
[NSDictionary dictionaryWithObjectsAndKeys: @ "redColor", @ "titleValue", [UIColor redColor], @ "colorValue", nil],
nil];


NSArray * otherColorList = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys: @ "RGB: 0.25/0/0", @ "@ titleValue", [UIColor colorWithRed: 0.25 green: 0 blue: 0 alpha: 1], @ "colorValue", nil],
[NSDictionary dictionaryWithObjectsAndKeys: @ "RGB: 0.5/0/0", @ "@ titleValue", [UIColor colorWithRed: 0.5 green: 0 blue: 0 alpha: 1], @ "colorValue", nil],
[NSDictionary dictionaryWithObjectsAndKeys: @ "RGB: 0.75/0/0", @ "@ titleValue", [UIColor colorWithRed: 0.75 green: 0 blue: 0 alpha: 1], @ "colorValue", nil],
nil
];

masterColorList = [NSArray arrayWithObjects: colorList, otherColorList, nil];
[MasterColorList retain];
}

return self;
}

- (NSInteger) numberOfSectionsInTableView: (UITableView *) tableView
{
return masterColorList.count;
}

/ *
- (NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section
{
return [[masterColorList objectAtIndex: section] count];
}
* /



- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath
{
static NSString * MyIdentifier = @ "MyIdentifier";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: MyIdentifier];

if (cell = nil)
{
cell = [[[UITableViewCell alloc] initWithFrame: CGRectZero reuseIdentifier: MyIdentifier] autorelease];
}

cell.textColor = [[[masterColorList objectAtIndex: indexPath.section] objectAtIndex: indexPath.row] objectForKey: @ "colorValue"];
cell.selectedTextColor = [[[masterColorList objectAtIndex: indexPath.section] objectAtIndex: indexPath.row] objectForKey: @ "colorValue"];
cell.text = [[[masterColorList objectAtIndex: indexPath.section] objectAtIndex: indexPath.row] objectForKey: @ "titleValue"];

return cell;
}

- (NSString *) tableView: (UITableView *) tableView titleForHeaderInSection: (NSInteger) section
{
if (section == 0)
{
return @ "SDK Colors";
}
else if (section == 1)
{
return @ "RGB Colors";
}
return 0;
}

- (Void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath
{
[[TableView cellForRowAtIndexPath: indexPath] setAccessoryType: UITableViewCellAccessoryCheckmark];
}

- (Void) dealloc
{
[Super dealloc];
[MasterColorList release];
}

- (Void) viewDidLoad
{
[Super viewDidLoad];
}


- (Void) viewWillAppear: (BOOL) animated
{
[Super viewWillAppear: animated];
}

- (Void) viewDidAppear: (BOOL) animated
{
[Super viewDidAppear: animated];
}

- (Void) viewWillDisappear: (BOOL) animated
{
}

- (Void) viewDidDisappear: (BOOL) animated
{
}

- (Void) didReceiveMemoryWarning
{
[Super didReceiveMemoryWarning];
}
@ End

Reply:
Back to the first floor, section should not exceed ah, can not test that function as long as there is even return a variable or function manual assignment is empty, will cause the program to hang. Do not: numberOfSections returns 2.

Back to the second floor, I put the code posted, trouble to help look ah, I do not know how to get the section.

3rd floor back, unable to test ah, that function will cause the program to hang
Reply:
In
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath
In,
if (cell == nil)
Less of an equal sign

After the judge sentences written proposals, written like this
if (nil == cell)

No comments:

Post a Comment