Im using this code to show an ABUnknowPersonViewController for showing a record from a person which was created from a vCard String:
- (ABRecordRef)person {
if (person == NULL) {
ABPersonCreator *creator = [[ABPersonCreator alloc] initWithVcardString:vcardString];
person = creator.person;
CFRetain(person);
[creator release];
}
return person;
}
- (UIView *)fullscreenView {
unknownPersonController = [[ABUnknownPersonViewController alloc] init];
unknownPersonController.displayedPerson = self.person;
unknownPersonController.allowsAddingToAddressBook = YES;
unknownPersonController.allowsActions = YES;
unknownPersonController.unknownPersonViewDelegate = self;
return unknownPersonController.view;
}
Can someone help me out with this?
thx Philip
The solution to this problem for me was that I wasn't passing the right stuff when building the ABRecordRef. For instance, I tried to simply set a string to a property when it instead wanted a kABMultiStringPropertyType. The exception would only occur after trying to launch the UnknownPersonViewController.
Check your datatypes and make sure that you're building the right thing.
Shouldn't have unknownPersonViewController have an autorelease, as it's view's returned?
Related
I have no idea why this isn't working and I feel it's something really very stupid.. I'm trying to compare two textfields (like a confirming the password type of thing) but it just isn't working!! Ive tried several different options and none of them work. I've tried:
if (passwordCheckField1.text == passwordCheckField2.text) {
[self performSegueWithIdentifier:#"segue4" sender:nil];
}
I've tried:
NSString *retrivedPasswordCheckField1 = passwordCheckField1.text;
NSString *retrivedPasswordCheckField2 = passwordCheckField2.text;
if ([retrivedPasswordCheckField1 isEqualToString:retrivedPasswordCheckField2]) {
[self performSegueWithIdentifier:#"segue4" sender:nil];
}
I've tried:
if ([passwordCheckField1.text isEqualToString:retrivedPasswordCheckField2.text]) {
[self performSegueWithIdentifier:#"segue4" sender:nil];
}
I've implement the <UITextFieldDelegate> in the .h and i've also set the delegates for both fields, (passwordCheckField1.delegate = self;
passwordCheckField2.delegate = self;)
What am I missing???? Thanks for your help!
EDIT
I probably should mention that I'm using a Navigation Controller, with several child view controllers. Each contains a text field, so when the view controller about the first password comes up, the user enters it and then clicks next taking them to the confirm password view controller. All are linked to the same class files.
This should work.
NSString *password = passwordCheckField1.text;
NSString *confirmPassword = passwordCheckField2.text;
NSLog(#"password: '%#'", password);
NSLog(#"confirmPassword: '%#'", confirmPassword);
if([password isEqualToString: confirmPassword]) {
NSLog(#"Match");
} else {
NSLog(#"Not Match");
}
if (passwordCheckField1.text == passwordCheckField2.text) {
[self performSegueWithIdentifier:#"segue4" sender:nil];
}
The above code doesn't compare two string values. It actually compares two pointers value.So it is not going to be useful for you.
but code
if ([retrivedPasswordCheckField1 isEqualToString:retrivedPasswordCheckField2]) {
[self performSegueWithIdentifier:#"segue4" sender:nil];
}
should have compared the string values. May be string your values are not same or nil. Have you printed the passwordCheckField1.text and passwordCheckField2.text.What is the values for two strings ?
chk your values.
if ([passwordCheckField1.text isEqualToString:passwordCheckField2.text]) {
//Match it's working for me
}
try this
if([[passwordCheckField1 text] isEqualToString:[passwordCheckField2 text]])
{
[self performSegueWithIdentifier:#"segue4" sender:nil];
}
else
{
//not matched
}
As a precautionary measure, try triming both the password strings for leading and trailing spaces before comparing like
NSString *pwd1 = [pwdTxtField1.text stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#" "]];
I have a TTableView. The items in this table a mapped to an url, so that when I click on an item, another view appear with informations about this item.
All these informations are attributes of a class. So, how can I build my TTableTextItem URL in order to transmit the class containing informations to the view responsible for the display of these informations ?
Thanks in advance.
One way of doing it is to use a TTURLAction. When the user selects a row in your table, which will call your didSelectObject (of TTTableViewController) method, extract the object or set of objects you want to pass and build a TTURLAction like this:
TTURLAction *action = [[[TTURLAction actionWithURLPath:#"tt://showUser"]
applyQuery:[NSDictionary dictionaryWithObject:user forKey:#"kParameterUser"]]
applyAnimated:YES];
Then open the action:
[[TTNavigator navigator] openURLAction:action];
The controller you want to open as a result of this action should be registered in your TTURLMap and should have a constructor thus:
- (id) initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query {
self = [super init];
if (self != nil) {
self.user = [query objectForKey:kParameterUser];
}
return self;
}
I tend to create categories on classes for objects I want to be able to open another controller and display themselves.
The big problem with directly using TTURLAction is that you can't really use them with TTTableViewItem. The only way to really do it is override -didSelectObject:atIndexPath: and build your custom TTURLAction with your desired object in the query dictionary. But this breaks the nice separation of Model and View Controller, and gets complicated once you have multiple objects to pass.
Instead of this, I've been using a small category which automatically takes the userInfo property of the table item (which I set to whatever I need), and automatically adds it as a URL parameter.
And then you use this to retrieve it in your mapped view controller.
- (id)initWithNavigatorURL:(NSURL *)URL query:(NSDictionary *)query {
if (self = [self initWithNibName:nil bundle:nil]) {
id myPassedObject = [query objectForKey:#"__userInfo__"];
// do the rest of your initlization
}
return self;
}
You can download it as a GitHub Gist here. The code is also below. We're considering merging this into the main branch at some point.
TTTableViewDelegate+URLAdditions.h
#interface TTTableViewDelegate(URLAdditions)
#end
TTTableViewDelegate+URLAdditions.m
#import "TTTableViewDelegate+URLAdditions.h"
#implementation TTTableViewDelegate(URLAdditions)
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
id<TTTableViewDataSource> dataSource = (id<TTTableViewDataSource>)tableView.dataSource;
id object = [dataSource tableView:tableView objectForRowAtIndexPath:indexPath];
// Added section to automatically wrap up any TTTableItem userInfo objects. If it is a dictionary, it gets sent directly
// If it is not, it is put in a dictionary and sent as they __userInfo__ key
if( [object isKindOfClass:[TTTableLinkedItem class]] ) {
TTTableLinkedItem* item = object;
if( item.URL && [_controller shouldOpenURL:item.URL] ) {
// If the TTTableItem has userInfo, wrap it up and send it along to the URL
if( item.userInfo ) {
NSDictionary *userInfoDict;
// If userInfo is a dictionary, pass it along else create a dictionary
if( [item.userInfo isKindOfClass:[NSDictionary class]] ) {
userInfoDict = item.userInfo;
} else {
userInfoDict = [NSDictionary dictionaryWithObject:item.userInfo forKey:#"__userInfo__"];
}
[[TTNavigator navigator] openURLAction:[[[TTURLAction actionWithURLPath:item.URL]
applyQuery:userInfoDict]
applyAnimated:YES]];
} else {
TTOpenURL( item.URL );
}
}
if( [object isKindOfClass:[TTTableButton class]] ) {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
else if( [object isKindOfClass:[TTTableMoreButton class]] ) {
TTTableMoreButton* moreLink = (TTTableMoreButton*)object;
moreLink.isLoading = YES;
TTTableMoreButtonCell* cell
= (TTTableMoreButtonCell*)[tableView cellForRowAtIndexPath:indexPath];
cell.animating = YES;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if( moreLink.model )
[moreLink.model load:TTURLRequestCachePolicyDefault more:YES];
else
[_controller.model load:TTURLRequestCachePolicyDefault more:YES];
}
}
[_controller didSelectObject:object atIndexPath:indexPath];
}
#end
I think the documentation on the official website does describe very clearly the navigation scheme for Three20. Your question is the very common task of any application, and Three20 provides powerful support for that.
I have little fix this awesome code :)
as posted version strip callback from TTTableButton.
Correction is:
if( [object isKindOfClass:[TTTableButton class]] ) {
if (item.delegate && item.selector) {
[item.delegate performSelector:item.selector withObject:object];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
I am getting the leaks as 100%. I don't know how to release the object after it returns
Could you explain the procedure how to release the allocated Titles object.
-(Titles *)listTiles
{
Tiles* tile = [[Tiles alloc] init];
tile.googleTile_X = (int)tileX;
tile.googleTile_Y = (int) pow(2, aZoom) - 1- tileY ;
tile.zoomLevel = aZoom;
return tile;
}
You're sending -alloc, and failing to send -release or -autorelease to the object you've created.
Read Apple's introductory documentation on memory management.
In general it depends, but in that particular case I believe you can use return [tile autorelease].
P.S.: Please format your code correctly.
-(Titles *)listTiles
{
Tiles* tile = [[[Tiles alloc] init] autorelease];
tile.googleTile_X = (int)tileX;
tile.googleTile_Y = (int) pow(2, aZoom) - 1- tileY ;
tile.zoomLevel = aZoom;
return tile;
}
I'm pretty new to OOP in general and just really started working with Obj-c a few months back. So, please be gentle! I appreciate your help in advance. Now to the question!
I have 3 Text Fields where a user inputs name, phone, and email.
I collect and place them in a label using an NSString like this [this is the one for the name]:
- (IBAction)changeGreeting:(id)sender {
self.name = textInput.text;
NSString *nameString = name;
if([nameString length] == 0) {
nameString = #"I Forgot";
}
NSString *greeting = [[NSString alloc]
initWithFormat:#"Hello, my name is %#! Really!", nameString];
label.text = greeting;
[greeting release];
}
With this I have been able to place the text from text.input into my label (as stated in label.text = greeting;)
I have another view where I'd like to have someone review this information (view a label too). I need to have access to name or Textinput.text in that other view.
How can I accomplish this?
If you don't need to communicate changes between the two view controllers, you may want to pass it in using a custom init method. This may be best for a confirmation screen, where the prompt would make no sense without this string.
- (id)initWithFrame:(CGRect)aRect username:(NSString*)aName {
if((self = [super initWithFrame:aRect])) {
_myName = [aName retain];
}
return self
}
Another option is to implement a method on the first view controller and call it from the second.
- (NSString*)enteredUsername {
return _myName;
}
I have 4 UITextFields that I'm dynamically creating, in the viewDidLoad, which works good. I want to reference those objects when the UISlider value changes. Right now I'm storing those objects in a NSMutableArray and accessing them like so from the sliderChanged method:
NSInteger labelIndex = [newText intValue];
labelIndex--;
NSUInteger firstValue = (int)0;
NSMutableArray *holeArray = [pointsArray objectAtIndex:labelIndex];
UITextField *textField = [textFieldArray objectAtIndex:firstValue];
NSString *newLabel1Text = [[NSString alloc] initWithString:[[holeArray objectAtIndex:firstValue] stringValue]];
[textField setText: newLabel1Text];
[newLabel1Text release];
Everything is working good, but the program crashes on the setText: method. The last message I get from the program is: [UILabel drawTextInRect:] and then I get a EXC_BAD_ACCESS failure.
I want to be able to acces that dynamically created UITextField, but I must be going about it the wrong way.
Thanks!
Uh, yea, you create a text field, but you aren't displaying the field itself, just creating it.
If you want to do what I think you want to do, I would just do if statements.
ex.
if (firstValue == 1)
{
fieldone.text = #"whatever";
}
else if (firstValue == 2)
{
fieldtwo.text = #"whatever";
}