Populating ViewBased table from data in 6 different NSMutable arrays - objective-c

I have 6 different NSMutable arrays [(Arr(A); Arr(B); etc.] each of which represents data for one cell of a row in the table. The array is essentially the key representation. They are built in a prior classes, passed to the current class and have exactly the same number of string objects (63) in each. The table is essential a data representation of
Questions:
Must I build a NSDictionary with 'keys' and 'objects'. How do I build thatDictionary. I have tried various methods stepping through a count loop with no success. I can to find a method for inserting objects for specific keys.
Can I load the table directly from the various arrays without a ViewController. I have the table and id's laid out but I have not been able to add a ViewController to this class - I only have 'Files Owner'. If this is easiest how can I do that.
If needed, how do I take elements of the 6 arrays in order as a comma delimited string in another array that becomes the input to a row of of the table and therefore parsed into the table.
No code to offer because all my attempts w/code have been unsuccessful.
NEED SOME SPECIFIC DIRECTION HERE.
.h
// ReportsOutput.h
// Stamp Collection
// Created by Terry Lengel on 4/20/15.
// Copyright (c) 2015 Terry Lengel. All rights reserved.
#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
#import "ReportsClass.h"
#interface ReportsOutput : NSWindowController <NSMenuDelegate,NSTableViewDataSource,NSTableViewDelegate,NSApplicationDelegate>{
// variable and outlet for the table
IBOutlet NSTableView *rptTable;
}
// data element sources
#property(nonatomic,strong) NSMutableArray *tblYrScott;
#property(nonatomic,strong) NSMutableArray *tblYrExt;
#property(nonatomic,strong) NSMutableArray *tblYrYear;
#property(nonatomic,strong) NSMutableArray *tblYrType;
#property(nonatomic,strong) NSMutableArray *tblYrPrice;
#property(nonatomic,strong) NSMutableArray *tblYrDescription;
// the Display data source array for the table
#property(strong) NSMutableArray *rptData;
#pragma mark - Method Declarations
-(BOOL)conditionData;
-(NSDictionary *)makeDictionaryRecord:(NSString*)scott withInfo:(NSString*)ext withInfo:(NSString*)year withInfo:(NSString*)type withInfo:(NSString*)price withInfo:(NSString*)Description;
#end
.m
// ReportsOutput.m
// Stamp Collection
// Created by Terry Lengel on 4/20/15.
// Copyright (c) 2015 Terry Lengel. All rights reserved.
#import "ReportsOutput.h"
#import "ReportsClass.h"
#interface ReportsOutput ()
#end
#implementation ReportsOutput
#synthesize tblYrScott;
#synthesize tblYrExt;
#synthesize tblYrType;
#synthesize tblYrPrice;
#synthesize tblYrYear;
#synthesize tblYrDescription;
#synthesize rptData;
-(id)initWithWindow:(NSWindow *)window{
self = [super initWithWindow:window];
if (self){
// initialize code here
}
return self;
}
-(void)windowDidLoad {
[super windowDidLoad];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}
-(void)applicationDidFinishLaunching:(NSNotification *)notification{
//Insert code here to initialize your application
}
// Terminate the app by using the RED button:
-(BOOL)applicationShouldTerminateAfterLastWindowClosed:
(NSApplication *)sender{
return YES;
}
-(void)awakeFromNib{
if (self.conditionData == YES){
[rptTable reloadData];
}
}
-(BOOL)windowShouldClose:(id)sender{
return YES;
}
-(void)performClose:(id)sender{
[self close];
}
#pragma mark - Table View Data Source
-(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView{
return rptData.count;
}
-(NSView *) tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
NSTableCellView *scott = [tableView makeViewWithIdentifier:#"Scott" owner:self];
scott.textField.stringValue = [self.rptData objectAtIndex:row];
return scott;
}
// request for sorting
-(void) tableView:(NSTableView *)tableView sortDescriptorsDidChange:(NSArray *)oldDescriptors{
// table view received sort request
//sort the data, then reload the tableView data:
[rptData sortUsingDescriptors:[rptTable sortDescriptors]];
[rptTable reloadData];
}
-(BOOL)conditionData{
BOOL conditionData = NO;
NSString *rPrice;
NSString *rExt;
NSString *rYear;
NSString *rType;
NSString *rDescription;
for (int b=0; b<[tblYrScott count]; ++b){
//condition source data to remove any null appearences
rExt = [tblYrExt objectAtIndex:b];
if (rExt == (id)[NSNull null] || rExt.length == 0 ){
rExt = #"None";
}else if ([rExt isEqualToString:#" "]){
rExt = #"None";
}else
rExt = [tblYrExt objectAtIndex:b];
rYear = [tblYrYear objectAtIndex:b];
if (rYear == (id)[NSNull null] || rYear.length == 0 ){
rYear = #" ";
}else
rYear = [tblYrYear objectAtIndex:b];
rType = [tblYrType objectAtIndex:b];
if (rType == (id)[NSNull null] || rType.length == 0 ){
rType = #" ";
}else
rType = [tblYrType objectAtIndex:b];
rPrice = [tblYrPrice objectAtIndex:b];
if (rPrice == (id)[NSNull null] || rPrice.length == 0 ){
rPrice = #"n/r";
}else
rPrice = [tblYrPrice objectAtIndex:b];
rDescription = [tblYrDescription objectAtIndex:b];
if (rDescription == (id)[NSNull null] || rDescription.length == 0 ){
rDescription = #" ";
}else
rDescription = [tblYrDescription objectAtIndex:b];
NSDictionary *rptData = #{#"Scott":[tblYrScott objectAtIndex:b],#"Ext":rExt,#"Year":rYear,#"Type":rType,#"Price":rPrice,#"Description":rDescription};
}
//[rptTable reloadData];
return conditionData = YES;
}
-(NSDictionary*) makeDictionaryRecord:(NSString *)scott withInfo: (NSString *)ext withInfo: (NSString *)year withInfo: (NSString *)type withInfo: (NSString *)price withInfo: (NSString *)description{
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:scott,#"Scott",ext,#"Ext",year,#"Year",type,#"Type",price,#"Price",description,#"Description", nil];
return dict;
}
#end
Data Sample:
2015-04-25 12:20:49.251 StampsProjectDev[2981:591183] rptData = {
Description = "Lunar New Year - Horse";
Ext = None;
Price = "n/r";
Scott = 4846;
Type = C;
Year = 2014;
}
2015-04-25 12:20:49.252 StampsProjectDev[2981:591183] rptData = {
Description = "Jimi Hendrix";
Ext = None;
Price = "n/r";
Scott = 4880;
Type = C;
Year = 2014;
}
2015-04-25 12:20:49.252 StampsProjectDev[2981:591183] rptData = {
Description = "Charlton Heston";
Ext = None;
Price = "n/r";
Scott = 4892;
Type = C;
Year = 2014;
}
2015-04-25 12:20:49.252 StampsProjectDev[2981:591183] rptData = {
Description = "Janice Joplin";
Ext = None;
Price = "n/r";
Scott = 4916;
Type = C;
Year = 2014;
}
2015-04-25 12:20:49.252 StampsProjectDev[2981:591183] rptData = {
Description = "Ralph Ellison";
Ext = None;
Price = "n/r";
Scott = 4866;
Type = C;
Year = 2014;
}

Must I build a NSDictionary with 'keys' and 'objects'. How do I build thatDictionary. I have tried various methods stepping through a count loop with no success. I can to find a method for inserting objects for specific keys.
Not required, but advisable.
// assume six arrays are array0, array1, ...
// assume array0.count == array1.count == etc
for (int i=0; i<array0.count; ++i) {
NSDictionary *di = #{ #"ar0":array0[i], #"ar1":array1[i],... };
}
But a better idea is an NSObject subclass that you create that is meaningful to your users and has properties from corresponding elements from the arrays (call it MeaningfulObject)....
// in your datasource's interface definition
#property(strong) NSMutableArray *myArrayOfMeaningfulObjects;
self.myArrayOfMeaningfulObjects = [#[] mutableCopy];
// assume array0.count == array1.count == etc
for (int i=0; i<array0.count; ++i) {
MeaningfulObject *mi = [MeaningfulObject meaningfulObjectWithAttribute0:array0[i] attribute1:array1[i]... ];
[self.myArrayOfMeaningfulObjects addObject:mi];
}
Can I load the table directly from the various arrays without a ViewController. I have the table and id's laid out but I have not been able to add a ViewController to this class - I only have 'Files Owner'. If this is easiest how can I do that.
The table loads itself. Your job is to provide it with a datasource, which is an array of objects representing rows. Most people opt to make the view controller who's view contains the table act as the datasource, but the table's datasource can be any object. The two required parts of the NSTableViewDatasource protocol are (1) numberOfRowsInTableView: like this:
return self.myArrayOfMeaningfulObjects.count;
And (2) tableView:viewForTableColumn:row: like this:
MeaningfulObject *mrow = self.myArrayOfMeaningfulObjects[indexPath.row];
// configure a tableview cell using mrow's attributes
cell.textLabel.text = mrow.attribute0;
If needed, how do I take elements of the 6 arrays in order as a comma delimited string in another array that becomes the input to a row of of the table and therefore parsed into the table.
Don't understand this one, but hopefully a good answer is implicit in the foregoing
EDIT, Upon review of the code, it seems to me that you've nearly got it. The code has declared an array that will be the basis of the datasource, like this:
#property(strong) NSMutableArray *rptData;
Good, but a consequential mistake is made here:
NSDictionary *rptData = #{#"Scott":[tblYrScott objectAtIndex:b],#"Ext":rExt,#"Year":rYear,#"Type":rType,#"Price":rPrice,#"Description":rDescription};
That's a dictionary which looks as if it represents a single row in the table, named confusingly like the NSArray property. It looks as if the dictionary is built then abandoned on the iteration of the loop, overwritten by the object for the next row. To make this work, the objects representing the rows must be added to the datasource, like this:
// renamed rptData dictionary to rowDictionary
NSDictionary *rowDictionary = #{#"Scott":[tblYrScott objectAtIndex:b],#"Ext":rExt,#"Year":rYear,#"Type":rType,#"Price":rPrice,#"Description":rDescription};
[self.rptData addObject:rowDictionary];

Related

How to parse and take only this string value

I wanted to get only array string value app. As example(SLGoogleAuth ,HalfTunes,TheBackgrounder,Calculiator) . But don't know how to do?
It's a code.
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//
Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
SEL selector=NSSelectorFromString(#"defaultWorkspace");
NSObject* workspace = [LSApplicationWorkspace_class performSelector:selector];
SEL selectorALL = NSSelectorFromString(#"allApplications");
NSLog(#"apps: %#", [workspace performSelector:selectorALL]);
}
It's output:
Thanks in advance
You do not want to parse that. NSLog prints out a description of an object. You want to access that value directly.
[LSApplicationWorkspace allApplications];
returns NSArray of LSApplicationProxy. LSApplicationProxy class has a ivar _bundleURL that contains information that you need. You need runtime functions to access it. Working example below:
// #import <objc/runtime.h>
Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
SEL selector=NSSelectorFromString(#"defaultWorkspace");
NSObject* workspace = [LSApplicationWorkspace_class performSelector:selector];
SEL selectorALL = NSSelectorFromString(#"allApplications");
NSArray* appProxies = [workspace performSelector:selectorALL];
Ivar bundleUrlIvar = class_getInstanceVariable([appProxies.firstObject class], "_bundleURL");
NSMutableString* result = [NSMutableString string];
for (id appProxy in appProxies)
{
NSURL* url = object_getIvar(appProxy, bundleUrlIvar);
// at this point you have the information and you can do whatever you want with it
// I will make it a list as you asked
if (url)
{
[result appendFormat:#",%#", [url lastPathComponent]];
}
}
if (result.length > 0)
{
// remove comma from beginning of the list
[result deleteCharactersInRange:NSMakeRange(0, 1)];
}
NSLog(#"apps: %#", result);
Note that this will be rejected by AppStore as you are using private apis. So use at your own discretion.

string not populating with array data, even though arrays are not really empty

I am trying to create a non-Document-based application for Mac OS X that randomizes cards for the game of Dominion.
From many of the ones I have tried, the only thing I cannot seem to do is limit the number of sets picked from a selection made by the user, and things worked pretty well in my program, but I am having issues.
I am trying to get the results to print in a custom view, but every time I look at the print preview, nothing shows, except header text, as specified in an NSMutableString.
This piece of code is what is being used to print and is found in MasterViewController:
- (IBAction)print:(id)sender
{
NSMutableString *content = [[NSMutableString alloc] initWithString:#"Cards\r\n\r\n"];
for (int i = 0; i < [supply.game count]; i++)
{
[content appendFormat:#"Card: %# Set: %# Cost: %d\r\n", [supply.game[i] name], [supply.game[i] collection], [supply.game[i] cost]];
}
[content appendFormat:#"\r\n\r\nRequired\r\n\r\n"];
for (int i = 0; i < [[setup supply] count]; i++)
{
NSDictionary* current = [setup supply][i];
NSString* key = [current allKeys][0]; // get the key of the current dictionary must be 0, as there is only one key
int value = [[current valueForKey:key] integerValue]; // variable to hold key value
if (value > 0) {
[content appendFormat:#"%#: %#", key, #"Yes"];
}
else
{
[content appendFormat:#"%#: %#", key, #"No"];
}
}
printView.content = [NSMutableString stringWithString:content];
[printView print:sender];
}
the data initially gets filled into some tableviews, which displays the correct content, and the supply.game array is the exact array that contains cards used for games.
setup is a property that refers to a view controller that populates a table with kinds of cards that may be required for games (e.g. shelters, colonies, ruins, spoils, and potions) and the supply method is supposed to return the array that view controller creates, which is itself not empty, as that table populates properly.
printView is a property that is assigned to a custom view found in MainMenu.xib and is the real view being used to print from.
the printView class looks like this:
header:
#import <Cocoa/Cocoa.h>
#interface PrintView : NSView
{
NSMutableString* content;
}
#property NSMutableString* content;
- (void)drawStringInRect:(NSRect)rect; // method to draw string to page
- (void)print:(id)sender; // method to print
#end
implementation:
#import "PrintView.h"
#implementation PrintView
#synthesize content;
- (BOOL)acceptsFirstResponder
{
return YES;
}
- (void)print:(id)sender
{
[[NSPrintOperation printOperationWithView:self] runOperation];
}
- (void)drawRect:(NSRect)dirtyRect {
NSGraphicsContext *context = [NSGraphicsContext currentContext];
if ([context isDrawingToScreen])
{
}
else
{
[[NSColor whiteColor] set];
NSRect bounds = [self bounds];
if (content == nil || [content length] == 0)
{
NSRectFill(bounds);
}
else
{
[self drawStringInRect:bounds];
}
}
}
- (void)drawStringInRect:(NSRect)rect
{
NSSize strSize; // variable to hold string size
NSPoint strOrigin; // variable used to position text
NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
[attributes setObject:[NSFont fontWithName:#"Helvetica" size:12] forKey:NSFontAttributeName];
[attributes setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName];
strSize = [content sizeWithAttributes:attributes];
strOrigin.x = rect.origin.x + (rect.size.width - strSize.width)/2;
strOrigin.y = rect.origin.y + (rect.size.height - strSize.height)/2;
[content drawAtPoint:strOrigin withAttributes:attributes];
}
#end
When I check the array sizes for printing operation, the size of the arrays is reported as zero, thus resulting in my current problem
If you need more code, here is code from Github, but I do not have the experimental branch up there, which is where the above code came from, though it should not be too different.
The MasterViewController will show how the supply.game array is made and SetupViewController houses the code that is used to determine what is needed in the game, as well as show how the supply array from [setup supply] is being produced.
MasterViewController has also been added as an object to MainMenu.xib, so I do not know if that affects anything.
Any idea of what I need to do?
Edit: Added in info that might be relevant

NSMutableDictionary - entries appear to be over-written by each addition

I'm fairly new to Objective-C; but have been coding for years and this one really stumps me.
I'm trying to build an iPhone app and wanted to create a "settings" screen which will use a Table format. (Xcode 5.1.1).
I want to future proof the main Settings screen and make it easy for the application coding by hiding the "hard work" in subroutines/methods.
I may be getting too clever but I've created a class for each 'setting' that contains screen prompts, default values etc and using an Enum to cross-reference it (so the compiler will highlight typos etc)
The problem I'm encountering is that when I add entries to my NSMutableDictionary and use lldb to print the values; every entry seems to have the same "key" and values. I've tried converting the eNum to an NSNumber and also as an NSString -- no difference in the result - so I'm obviously doing something else daft but just can't see it
The following code is from various .m & .h files, I've omitted boring stuff that you always "have to have" to keep it short
// basic x-ref I want to use in my code
typedef NS_OPTIONS(NSInteger, ConfigurationType) {
unDefined = -1,
Server = 0,
Id = 1,
Phone = 2
};
// definition for a "single" Settings value
#interface SettingDefinition : NSObject
#end
#implementation SettingDefinition
ConfigurationType _cfgType;
NSString *_cfgName;
NSString *_screenTitle;
NSString *_value;
- (NSString *)description
{
NSString *className = NSStringFromClass([self class]);
return [NSString stringWithFormat:#"<%#: x%p Type=%d dbKey=%# '%#' -> %#>", className, self, _cfgType, _cfgName, _screenTitle, _value];
}
- (id)initType:(ConfigurationType)cfgOption
withDbKey: (NSString*)dbKey
asOptionTitle:(NSString*)cfgTitle
withValue:(NSString*)itmValue
{
self = [super init];
if (self) {
_screenTitle = cfgTitle;
_cfgName = dbKey;
_cfgType = cfgOption;
_value = itmValue;
}
return self;
}
#end
#interface Configuration : NSObject
#end
#implementation Configuration {
NSMutableDictionary *Settings; // List of Setting structures
};
- (id)init {
self = [super init];
if (self) {
Settings = [[NSMutableDictionary alloc]init];
[self add:Server withDbKey:#"Server" asOptionTitle:#"Server"];
[self add:Id withDbKey:#"Id" asOptionTitle:#"Your ID"];
[self add:Phone withDbKey:#"Phone" asOptionTitle:#"Phone No."];
}
return self;
}
- (void) add:(ConfigurationType)cfgOption
withDbKey:(NSString*)dbKey
asOptionTitle:(NSString*)cfgTitle
{
NSString * itmValue = [self configurationValue: cfgOption cfgName:dbKey];
SettingDefinition *x = [[SettingDefinition alloc]
initType: cfgOption
withDbKey: dbKey
asOptionTitle: cfgTitle
withValue: itmValue];
[Settings setObject:x forKey:[self asKey:cfgOption]];
}
- (NSString *) asKey:(ConfigurationType) settingType {
NSString *rc = [NSString stringWithFormat:#"%d", settingType];
return rc;
}
- (NSString *) configurationValue:(ConfigurationType) settingType {
// returns a suitable value from my system setup
// which is initially a null value until the user sets everything up
}
the debug window shows the following when I break after the final call to [self add: ...]
(lldb) po Settings
{
0 = "<SettingDefinition: x0x8e7c280 Type=2 dbKey=Phone 'Phone No.' -> (null)>";
1 = "<SettingDefinition: x0x8c703a0 Type=2 dbKey=Phone 'Phone No.' -> (null)>";
2 = "<SettingDefinition: x0x8e7c310 Type=2 dbKey=Phone 'Phone No.' -> (null)>";
}
The (null) is obviously due to no data in 'value' yet; but why do they all show as 'Phone'; if I break after the second call to [self add:..] they all show as 'Id'
UPDATE:
DOH! obviously they're globals (I've been using another IDE where everything is local until exposed) .. If I enclose them in braces in the implementation as the documentation states then the exhibited problem vanishes. I have properties to access the variables but as the setter does more than just set the memory, I thought I'd need my "own" variables to hold the data.. said it was something daft .. thank you!

UILabel Address label is blank and Local Declaration hides instance variable

I am new to Xcode, and I am attempting to have my app access the Address Book, choose a person, and then create NSString values for the person (First Name, Last Name, Organization, Address, Email and Telephone Number) I can pull the first and last name, the organization, the first email entered (it would be nice to display all of the email address, and let the user choose), and the first phone number entered in (again, it would be nice to be able to choose), but the address for the person is always blank. I would really appreciate any help you can provide. In addition, I keep getting local declaration hides instance variable warnings - I have no idea how to resolve these.
#import "TACustomer.h"
#interface TACustomer ()
#end
#implementation TACustomer
#synthesize custfirstName;
#synthesize custlastName;
#synthesize custOrganization;
#synthesize custEmail;
#synthesize custAddress;
#synthesize custphoneNumber;
- (IBAction)showPicker:(id)sender
{
// Creating the Address Book Picker
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
// Place the delegate of the picker to the control.
picker.peoplePickerDelegate = self;
// Showing the picker.
[self presentModalViewController:picker animated:YES];
}
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
//assigning control back to the main controller.
[self dismissModalViewControllerAnimated:YES];
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
[self displayPerson:person];
[self dismissModalViewControllerAnimated:YES];
return NO;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
// Only inspect the value if it's an address.
if (property == kABPersonAddressProperty)
{
//Set up an ABMultiValue to hold the address values; copy from a book record.
ABMutableMultiValueRef multicustValue = ABRecordCopyValue(person, property);
// Set up an NSArray and copy values into it.
NSArray *thecustArray = (__bridge id)ABMultiValueCopyArrayOfAllValues(multicustValue);
// Figure out which values we want and store the index.
const NSUInteger customerIndex = ABMultiValueGetIndexForIdentifier (multicustValue, identifier);
// Set up an NSDictionary to hold the contents of the array.
NSDictionary *custDict = [thecustArray objectAtIndex:customerIndex];
// Set up NSStrings to hold the keys and values. First, how many are there?
const NSUInteger theCount = [custDict count];
NSString * __unsafe_unretained keys[theCount];
NSString *__unsafe_unretained values[theCount];
// Get the keys and values from the CFDictionary.
[custDict getObjects:values andKeys:keys];
// Set the address label's text.
NSString *customeraddress;
customeraddress = [NSString stringWithFormat:#"%#, %#, %#, %#, %#",
[custDict objectForKey:(NSString *)kABPersonAddressStreetKey],
[custDict objectForKey:(NSString *)kABPersonAddressCityKey],
[custDict objectForKey:(NSString *)kABPersonAddressStateKey],
[custDict objectForKey:(NSString *)kABPersonAddressZIPKey],
[custDict objectForKey:(NSString *)kABPersonAddressCountryKey]];
self.custAddress.text = customeraddress;
}
return NO;
}
- (void)displayPerson:(ABRecordRef)person
{
// Get Customer First Name
NSString* custfirstname = (__bridge_transfer NSString*)ABRecordCopyValue(person,kABPersonFirstNameProperty);
self.custfirstName.text = custfirstname;
// Get Customer Last Name
NSString* custlastname = (__bridge_transfer NSString*)ABRecordCopyValue(person,kABPersonLastNameProperty);
self.custlastName.text = custlastname;
// Get Customer Organization
NSString* custorganization = (__bridge_transfer NSString*)ABRecordCopyValue(person,kABPersonOrganizationProperty);
self.custOrganization.text = custorganization;
//Get Customer Email Address
NSString* custemail = nil;
ABMultiValueRef custemailAddresses = ABRecordCopyValue (person,kABPersonEmailProperty);
if (ABMultiValueGetCount(custemailAddresses) > 0)
{
custemail = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(custemailAddresses, 0);
} else
{
custemail = #"[None]";
}
self.custEmail.text = custemail;
CFRelease(custemailAddresses);
// Get Customer Phone Number
NSString* custphone = nil;
ABMultiValueRef phoneNumbers = ABRecordCopyValue (person,kABPersonPhoneProperty);
if (ABMultiValueGetCount(phoneNumbers) > 0)
{
custphone = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers, 0);
} else
{
custphone = #"[None]";
}
self.custphoneNumber.text = custphone;
CFRelease(phoneNumbers);
bundle:nil;
//[self.navigationController pushViewController:tempExamInfoView animated:YES];
}
#end
I have no answer for the problem that the address data is blank.
To get rid of the "local declaration hides instance variable" warning you need to use different variable names that do not clash with the names of the properties you are synthesizing.
For instance, in displayPerson: you have a local variable custfirstname. Because this uses the same name as a property, the local variable hides the instance variable of the same name that is being synthesized.
If you want to keep the local variable name, I believe it is also possible to tell #synthesize to use a different name for the instance variable that it generates. I am not familiar with the syntax, so if you want to go that way you have to look it up yourself.

TitleForHeaderInSection throwing EXC_BAD_ACCESS

I am trying to create a generic UITableView in my iPhone app.
I have a UITableView which populates the data using an array via a SELECT query loop.
I add the data into my array and populate the array in cellForRowAtIndexPath:.
I get the section header using that array and by using a sort method, I put the section headers in Array1.
I would like to have titleForHeaderInSection: work by having section 0 be a static header name and sections 1 and later become generic, meaning the header name will come from Array1.
I am not sure how can I create that logic since the app always throws EXC_BAD_ACCESS with the code below.
My logic: I keep the count of the array in an int and see if the value is greater than 0. If it is, I add the section header for and objectAtIndex:0, otherwise I use the static one. But when the count gets to 2, for section 2 and objectAtIndex:1, it breaks and throws EXC_BAD_ACCESS.
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
int value = [[self Array1] count];
if(section == 0)
return #"Countries";
if (value > 0) {
if (section == value){
return [[self Array1] objectAtIndex:section - 1];
}
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
int count = [[self Array1] count];
return count + 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
int value = [[self Array1] count];
if (section == 0) {
return [self.Array count];
}
if (value > 0) {
if (section == [[self Array1] count]) {
NSString *initialLetter = [[self Array1] objectAtIndex:section - 1];
// get the array of elements that begin with that letter
NSArray *elementsWithInitialLetter = [self elementsWithInitialLetter:initialLetter];
// return the count
return [elementsWithInitialLetter count];
}
}
}
Looks like you're just missing a retain on the iVar backing the Array1 method. declare the array as a property:
#property (nonatomic, retain) NSArray* datastore;
Then cache the value you're referring to in the Array1 method in this method (probably in viewDidLoad).
self.datastore = [self Array1];
Then replace all remaining references to [self Array1] with self.datastore. Build run and see if it still crashes. (Don't forget to set self.datastore = nil in your dealloc!