How can we set the button title for a button,i know this answer its simple,we need to set the title of the button for title ,but my need is somewhat diffrent ,i had a username which dynamically changes according to login.i set this in a button click and display it in a label within that button .my code for this is
- (void)getFacebookProfileFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
NSLog(#"Got Facebook Profile: %#", responseString);
NSString *likesString;
NSMutableDictionary *responseJSON = [responseString JSONValue];
NSString *username;
NSString *firstName = [responseJSON objectForKey:#"first_name"];
NSString *lastName = [responseJSON objectForKey:#"last_name"];
if (firstName && lastName) {
username = [NSString stringWithFormat:#"%# %#", firstName, lastName];
} else {
username = #"mysterious user";
}
[_loginButton setTitle:username forState:UIControlStateNormal];
_lblfaceusername.text = username;
[self refresh];
}
i need to display the user name in another button click and have to assing the title of that button to user name the code for this is
- (void)refresh {
if (_loginState == LoginStateStartup || _loginState == LoginStateLoggedOut) {
_loginStatusLabel.text = #"Not connected to Facebook";
[_loginButton setTitle:#"Login" forState:UIControlStateNormal];
_loginButton.hidden = NO;
} else if (_loginState == LoginStateLoggingIn) {
_loginStatusLabel.text = #"Connecting to Facebook...";
_loginButton.hidden = YES;
} else if (_loginState == LoginStateLoggedIn) {
_loginStatusLabel.text = #"Connected to Facebook";
[_loginButton setTitle:#"" forState:UIControlStateNormal];
_loginButton.hidden = NO;
}
}
i need to set the username in the [_loginButton setTitle:#"" forState:UIControlStateNormal];i want [_loginButton setTitle:username forState:UIControlStateNormal];
Anyhow you have set the button title in the method
- (void)getFacebookProfileFinished:(ASIHTTPRequest *)request
after facebook request done. Then, why you need to set that again in refresh method? Just comment out the line in LoginStateLoggedIn condition in refresh method.
//[_loginButton setTitle:#"" forState:UIControlStateNormal];
Edit
- (void)refresh {
if (_loginState == LoginStateStartup || _loginState == LoginStateLoggedOut) {
_loginStatusLabel.text = #"Not connected to Facebook";
[_loginButton setTitle:#"Login" forState:UIControlStateNormal];
_loginButton.hidden = NO;
} else if (_loginState == LoginStateLoggingIn) {
_loginStatusLabel.text = #"Connecting to Facebook...";
_loginButton.hidden = YES;
} else if (_loginState == LoginStateLoggedIn) {
_loginStatusLabel.text = #"Connected to Facebook";
NSString *username = [_loginButton titleForState:UIControlStateNormal];
[_loginButton setTitle:username forState:UIControlStateNormal];
_loginButton.hidden = NO;
}
}
What you need is storing a reference to that message at a location that both pieces of code can access. The typical way to do so is to add a NSString * _username in your interface definition, and setting it to the username when you receive it. That way you can always access it from any location that depends on the current value of it.
Memory management included, that would yield:
[_username release]; // Release possible previous login
_username = [username retain]; // Ownership needed
In refresh:
[_loginButton setTitle:_username forState:UIControlStateNormal];
In dealloc:
[_username release]; // Release ownership when not needed anymore
This allows you to access your variable at any location desired.
Related
While I'm am trying FBLoginView is not working. The button is not even shown any response while clicked. This is the code which I used:
#import <FacebookSDK/FacebookSDK.h>
#interface myaccount ()<FBLoginViewDelegate>
- (void)viewDidLoad
{
FBLoginView *loginview =[[FBLoginView alloc] init];
loginview.frame = btn1.frame;
for (id obj in loginview.subviews)
{
if ([obj isKindOfClass:[UIButton class]])
{
btn1 = obj;
[btn1 setBackgroundColor:UIColorFromRGB(0x3b5999)];
[btn1 sizeToFit];
}
}
loginview.delegate = self;
[scrol addSubview:loginview];
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user
{
logu.name = [NSString stringWithFormat:#"%#!", user.first_name];
logu.profilePic.profileID = user.id;
profilePicker.profileID = user.id;
self.loggedInUser = user;
}
}
Please help me to sort it out?
you can implement facebook in your application via using Graph Api .
create object of Graph api and set permission like
NSString *client_id = #"124262614407976";
if(reachabilityFlags==TRUE)
{
#try {
self.fbGraph = [[FbGraph alloc] initWithFbClientID:client_id];
[self.fbGraph authenticateUserWithCallbackObject:self
andSelector:#selector(fbGraphCallback:) andExtendedPermissions:#"user_photos,user_videos,
publish_stream,offline_access,user_checkins,
friends_checkins" andSuperView:self.window];
}
#catch (NSException *exception) {
// NSLog(#"Net not available %#",exception.userInfo);
}
#finally {
}
}
-- After it check call back.
- (void)fbGraphCallback:(id)sender
{
if ( (fbGraph.accessToken == nil) || ([fbGraph.accessToken length] == 0) ) {
NSLog(#"You pressed the 'cancel' or 'Dont Allow' button, you are NOT logged into Facebook...I require you to be logged in & approve access before you can do anything useful....");
//restart the authentication process.....
[fbGraph authenticateUserWithCallbackObject:self andSelector:#selector(fbGraphCallback:)
andExtendedPermissions:#"user_photos,user_videos,publish_stream,offline_access,user_checkins,friends_checkins"];
} else
{
// NSLog(#"------------>CONGRATULATIONS<------------, You're logged into Facebook... Your oAuth token is: %#", fbGraph.accessToken);
}
}
//////// you can find friend feed ..
-(void)getMeFeedButtonPressed{
if(delegate.fbGraph.accessToken!=nil)
{
NSString *customString=[NSString stringWithFormat:#"me"];
NSLog(#"here responce is for %#",customString);
FbGraphResponse *fb_graph_response = [delegate.fbGraph doGraphGet:customString withGetVars:nil];
NSLog(#"getMeFeedButtonPressed: %#", fb_graph_response.htmlResponse);
//parse our json
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];
// [facebook_response ]
[parser release];
// MyID=[facebook_response objectForKey:#"id"] ;
[MyID appendString:[facebook_response objectForKey:#"id"]];
NSLog(#"name %#",[facebook_response objectForKey:#"name"]);
NSString * url = [NSString stringWithFormat:#"https://graph.facebook.com/%#/picture",MyID];
NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
UIImage *downloadedImage = [UIImage imageWithData:data];
NSData *myEncodedImages = [NSKeyedArchiver archivedDataWithRootObject:downloadedImage];
[[NSUserDefaults standardUserDefaults ] setObject:myEncodedImages forKey:#"MYFBIMAGE"];
[self postData];
}else
{
#try {
[delegate.fbGraph authenticateUserWithCallbackObject:self andSelector:#selector(fbGraphCallback:)
andExtendedPermissions:#"user_photos,user_videos,publish_stream,offline_access,user_checkins,friends_checkins,email"];
}
#catch (NSException *exception) {
NSLog(#"Net not available");
}
#finally {
}
}
}
Hi I m creating a project where multiple Images Loading from Server With some like Count and Comment Count and a Button to like the image. I m showing the individual Images With using a Slider Controller like PageControl.
this is My code for Showing the View
-(UIView*)reloadView:(DPSliderView *)sliderView viewAtIndex:(NSUInteger)idx
{
_loading_view.hidden=TRUE;
if (idx < [photos count]) {
NSDictionary *item = [photos objectAtIndex:idx];
PhotoView *v = [[PhotoView alloc] init];
v.photoIndex = idx;
v.imageView.imageURL = [DPAPI urlForPhoto:item[#"photo_220x220"]];
NSString *placename1 = [item valueForKeyPath:#"spotting.item.name"];
NSString *firstCapChar1 = [[placename1 substringToIndex:1] capitalizedString];
NSString *cappedString1 = [placename1 stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:firstCapChar1];
v.spotNameLabel.text = cappedString1;
NSString *placename = [item valueForKeyPath:#"spotting.place.name"];
NSString *firstCapChar = [[placename substringToIndex:1] capitalizedString];
NSString *cappedString = [placename stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:firstCapChar];
NSString *place1=[NSString stringWithFormat:#"%#",cappedString];
NSString *address=[NSString stringWithFormat:#"%#",[item valueForKeyPath:#"spotting.place.address"]];
NSString *location_str3 = [NSString stringWithFormat:#"# %#, %#",place1,address];
int cap_len=[place1 length];
int address_lenth=[address length];
ZMutableAttributedString *str = [[ZMutableAttributedString alloc] initWithString:location_str3
attributes:[NSDictionary dictionaryWithObjectsAndKeys:
[[FontManager sharedManager] zFontWithName:#"Lucida Grande" pointSize:12],
ZFontAttributeName,
nil]];
[str addAttribute:ZFontAttributeName value:[[FontManager sharedManager] zFontWithName:#"Lucida Grande" pointSize:12] range:NSMakeRange(0, cap_len+3)];
[str addAttribute:ZForegroundColorAttributeName value:[UIColor colorWithRed:241/255.0f green:73.0/255.0f blue:2.0/255.0f alpha:1.0]range:NSMakeRange(0, cap_len+3)];
[str addAttribute:ZForegroundColorAttributeName value:[UIColor colorWithRed:128.0/255.0f green:121.0/255.0f blue:98.0/255.0f alpha:1.0]range:NSMakeRange(cap_len+4, address_lenth)];
v.placefontlabel.zAttributedText=str;
v.likesCountLabel.text = [NSString stringWithFormat:#"%i", [item[#"likes_count"] intValue]];
if ([_device_lang_str isEqualToString:#"es"])
{
v.shightingsLabel.text = [NSString stringWithFormat:NSLocalizedString(#"%i Vistas", nil), [item[#"sightings_count"] intValue]];
}
else
{
v.shightingsLabel.text = [NSString stringWithFormat:NSLocalizedString(#"%i Sightings", nil), [item[#"sightings_count"] intValue]];
}
if ([nolocationstr isEqualToString:#"YES"])
{
v.distanceLabel.text =[NSString stringWithFormat:#"%.2f km", [item[#"distance"] floatValue]];
}
else
{
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:[[item valueForKeyPath:#"spotting.place.lat"]floatValue] longitude:[[item valueForKeyPath:#"spotting.place.lng"] floatValue]];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:[_explore_lat_str floatValue] longitude:[_explore_lng_str floatValue]];
NSString *lat_laong=[NSString stringWithFormat:#"%f",[location1 distanceFromLocation:location2]];
int km=[lat_laong floatValue]*0.001;
NSString *distancestr=[NSString stringWithFormat:#"%d km",km];
float dist=[distancestr floatValue];
v.distanceLabel.text = [NSString stringWithFormat:#"%.2f km", dist];
}
if (![item[#"likes"] boolValue]) {
v.likeButton.enabled = YES;
v.likeButton.tag = idx;
[v.likeButton setImage:[UIImage imageNamed:#"like_new.png"] forState:UIControlStateNormal];
[v.likeButton addTarget:self action:#selector(likeAction:) forControlEvents:UIControlEventTouchUpInside];
}
else
{
v.likeButton.tag = idx;
[v.likeButton setImage:[UIImage imageNamed:#"like_new1.png"] forState:UIControlStateNormal];
}
NSArray *guides = item[#"guides"];
if ([guides count] > 0) {
NSString *guideType = [[guides objectAtIndex:0] valueForKey:#"type"];
UIImage *guidesIcon = [UIImage imageNamed:[NSString stringWithFormat:#"%#.png", guideType]];
v.guideButton.hidden = NO;
v.guideButton.tag = idx;
[v.guideButton setImage:guidesIcon forState:UIControlStateNormal];
[v.guideButton addTarget:self action:#selector(guideAction:) forControlEvents:UIControlEventTouchUpInside];
}
v.shareButton.tag = idx;
[v.shareButton addTarget:self action:#selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(photoTapGesture:)];
[v addGestureRecognizer:tapGesture];
[tapGesture release];
return [v autorelease];
} else {
UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"sc_img.png"]];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.center = CGPointMake(CGRectGetMidX(iv.bounds), 110);
[indicator startAnimating];
[iv addSubview:indicator];
[indicator release];
return [iv autorelease];
}
}
Now My question is :
If i will Click on Like Button , Then i have to change the button image as well as like count. I can able to Change the Button Image By This Method
[sender setImage:[UIImage ImageNamed:#"image.png"]];
But How can I change the Like count of the Label ? How can i access the Particular label of the View ? I have assigned the tag But , I dont know how to assign it.I dont want to Reload Whole Slider as the Photo are loading from Network (Remote Server) . Thanks for your Time.
Just keep a reference to the label and update that.
// #interface
#property (nonatomic, strong) UILabel *myLabel;
// #implementation
_myLabel.text = #"Whatever.";
If you have multiple labels, set the tags when you create your views
newView.tag = sequenceNumber +100;
And then update
-(void)updateLabelWithTag:(NSInteger)tag {
UILabel *label = (UILabel*) [self.scrollView viewWithTag:tag];
label.text = #"Whatever.";
}
I have the following program structure:
-(UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
...
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
...
...
if(condition)
{
do something;
}
else
{
if(condition)
{
unFollowButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
unFollowButton.frame = CGRectMake(180, 10, 120, 30);
unFollowButton.titleLabel.font = [UIFont systemFontOfSize:12];
unFollowButton.tag = indexPath.row;
unFollowButton.titleLabel.textColor = [UIColor blackColor];
[unFollowButton addTarget:self action:#selector(buttonClicked2:) forControlEvents:UIControlEventTouchUpInside];
NSLog(#"fCheckRowCheck Value in if Condition %#",fCheckRowCheck);
[unFollowButton setTitle:#"UnFollow" forState:UIControlStateNormal];
[cell.contentView addSubview:unFollowButton];
buttonValue = 0;
NSLog(#"buttonValue %d", buttonValue);
}
else
{
followButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
followButton.frame = CGRectMake(180, 10, 120, 30);
followButton.titleLabel.font = [UIFont systemFontOfSize:12];
followButton.tag = indexPath.row;
followButton.titleLabel.textColor = [UIColor blackColor];
[followButton setTitle:#"Follow" forState:UIControlStateNormal];
[followButton addTarget:self action:#selector(buttonClicked1:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:followButton];
buttonValue = 1;
NSLog(#"buttonValue %d", buttonValue);
}
}
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [self.infos objectAtIndex:row];
return cell;
}
- (IBAction)buttonClicked2:(UIButton *)sender
{
NSLog(#"BUTTON_CLICKED");
NSIndexPath *indexPath = [folksFolksTable indexPathForCell:(UITableViewCell*) [[sender superview]superview]];
NSLog(#"[sender tag] is %d", [sender tag]);
....
....
....
//Set up URLConnection tp send information on button click
NSMutableString *postString = [NSMutableString stringWithString:kUnFollowURL];
[postString appendString: [NSString stringWithFormat:#"?%#=%#", kId, [user objectForKey:#"id"] ]];
[postString appendString: [NSString stringWithFormat:#"&%#=%#", kfId, [fId objectForKey:#"fID"] ]];
[postString setString: [postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(#"post string = %#", postString);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:postString]];
[request setHTTPMethod:#"POST"];
followConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
NSLog(#"postconnection: %#", followConnection);
//Get Response from server
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: postString ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
NSLog(#"serverOutput = %#", serverOutput);
//Change the button lable from unfollow to follow
[sender setTitle:#"Follow" forState:UIControlStateNormal];
if([sender tag]==indexPath.row)
{
textField = (UITextField*)[cell viewWithTag:[sender tag]];
NSLog(#"txtF is %#",textField);
textField.hidden=NO;
}
}
- (IBAction)buttonClicked1:(UIButton *)sender
{
similar to buttonClicked 2
}
What I need is that the button should perform the corresponding action as well after the label has changed during runtime.
For example, I am following someone [ button label unfollow], if i click on the button [ button label becomes follow at that instant ( which is happening perfectly OK ). Now when i click the same button again with "follow" label, it is throwing exception.
How to go about it. Please help me figure it out ?
I'm new to iOS but:
Set a property that has the button state, or extend the button (some people don't recommend)
When it changes state, change the color and the label.
Wouldn't that work. Probably other users have better solutions.
Cheers.
EDIT: solved it. I had added previously the following line of code after
[sender setTitle:#"Follow" forState:UIControlStateNormal];
[sender addTarget:self action:#selector(buttonClicked2:) forControlEvents:UIControlEventTouchUpInside];
cause of exception was i added colon (:) twice after #selector(buttonClicked2) whereas i need only one colon.
I hope this question serves as reference to other users as well.
I have a reader application which can post text to Facebook .I already done that,i have a login-button as same as the facebook-login button,the user can login there and i retrieve the username from the Facebook and display instead of loge-out button,that means when the user login and came back the login-button title changes to loge-out thats the default behavior of the Facebook connect button,but i changed a little and set the title as username of the correspondent user.My problem is after login to the Facebook the the title of the button changes to username,but after redirected to some other page of the application and comes back it doesn't show the username the button title shows login.I tried a lot to solve this i even uses the NSUserDefault but no luck my entire code for this is
- (IBAction)loginButtonTapped:(id)sender
{
NSString *appId = #"HIDDEN1234";
NSString *permissions = #"publish_stream";
if (_loginDialog == nil) {
self.loginDialog = [[[FBFunLoginDialog alloc] initWithAppId:appId requestedPermissions:permissions delegate:self] autorelease];
self.loginDialogView = _loginDialog.view;
}
if (_loginState == LoginStateStartup || _loginState == LoginStateLoggedOut) {
_loginState = LoginStateLoggingIn;
[_loginDialog login];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"FB_logged"];
} else if (_loginState == LoginStateLoggedIn) {
_loginState = LoginStateLoggedOut;
_btnFacebookmain.enabled =NO;
[_loginDialog logout];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:#"FB_logged"];
}
[self refresh];
}
-(IBAction)_clickbtnFaacbukMain:(id)sender
{
StatusViewController *detailViewController = [[StatusViewController alloc] initWithNibName:#"StatusViewController" bundle:nil];
detailViewController.yourStringProperty = localStringValue;
detailViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:detailViewController animated:YES];
[UIView commitAnimations];
[detailViewController release];
UIView *popView = (UIView *)[self.view viewWithTag:106];
//ViewWithTag Number should be same as used while allocating
[popView removeFromSuperview];
}
- (void)refresh {
if (_loginState == LoginStateStartup || _loginState == LoginStateLoggedOut) {
_loginStatusLabel.text = #"Not connected to Facebook";
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:#"FB_logged"];
[_loginButton setTitle:#"" forState:UIControlStateNormal];
UIImage *buttonImage = [UIImage imageNamed:#"settings_connect1-facebook-icon"];
[_loginButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
//[[NSUserDefaults standardUserDefaults]removeObjectForKey:#"FB_LOGIN_STATUS"];
_loginButton.hidden = NO;
} else if (_loginState == LoginStateLoggingIn) {
_loginStatusLabel.text = #"Connecting to Facebook...";
_loginButton.hidden = YES;
UIImage *buttonImage = [UIImage imageNamed:#"settings_connect1-facebook-icon"];
[_loginButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
} else if (_loginState == LoginStateLoggedIn) {
_loginStatusLabel.text = #"Connected to Facebook";
NSString *username = [_loginButton titleForState:UIControlStateNormal];
[_loginButton setTitle:username forState:UIControlStateNormal];
[_loginButton setBackgroundImage:nil forState:UIControlStateNormal];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"FB_logged"];
_loginButton.hidden = NO;
}
}
- (void)getFacebookProfile {
NSString *urlString = [NSString stringWithFormat:#"https://graph.facebook.com/me?access_token=%#", [_accessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDidFinishSelector:#selector(getFacebookProfileFinished:)];
[request setDelegate:self];
[request startAsynchronous];
}
#pragma mark FB Responses
- (void)getFacebookProfileFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
NSLog(#"Got Facebook Profile: %#", responseString);
NSMutableDictionary *responseJSON = [responseString JSONValue];
NSString *username;
NSString *firstName = [responseJSON objectForKey:#"first_name"];
NSString *lastName = [responseJSON objectForKey:#"last_name"];
if (firstName && lastName) {
username = [NSString stringWithFormat:#"%# %#", firstName, lastName];
} else {
username = #"mysterious user";
}
//[[NSUserDefaults standardUserDefaults] setObject:#"username" forKey:#"FB_LOGIN_STATUS"];
[_loginButton setTitle:username forState:UIControlStateNormal];
[self refresh];
}
#pragma mark FBFunLoginDialogDelegate
- (void)accessTokenFound:(NSString *)accessToken {
NSLog(#"Access token found: %#", accessToken);
self.accessToken = accessToken;
_loginState = LoginStateLoggedIn;
[self dismissModalViewControllerAnimated:YES];
[self getFacebookProfile];
[self refresh];
}
- (void)displayRequired {
[self presentModalViewController:_loginDialog animated:YES];
}
- (void)closeTapped {
[self dismissModalViewControllerAnimated:YES];
_loginState = LoginStateLoggedOut;
[_loginDialog logout];
[self refresh];
}
and in viewwillapper method
BOOL loggedd = [[NSUserDefaults standardUserDefaults] boolForKey:#"FB_logged"];
if (loggedd == YES) {
_btnFacebookmain.enabled = YES;
NSString *username = [_loginButton titleForState:UIControlStateNormal];
[_loginButton setTitle:username forState:UIControlStateNormal];
//[self refresh];
}
else
{
[_loginButton setTitle:#"" forState:UIControlStateNormal];
_btnFacebookmain.enabled =NO;
/* UIImage *buttonImage = [UIImage imageNamed:#"settings_connect1-facebook-icon"];
[_loginButton setBackgroundImage:buttonImage forState:UIControlStateNormal];*/
}
please look into this code and help me to solve this.
Thanks in advance.
I want to save, after user press send mail button, the mail addresses an user wrote. But even if it could be set the to recipient I don't know how to read from it (there aren't any properties, or better any read enabled one, related to toRecipient). Any suggestions?
I don't think there is any way to do that.
I find a way:
Code
MFMailComposeViewController *mViewController = [[MFMailComposeViewController alloc] init];
NSArray* listVues = [mViewController childViewControllers];
MFMailComposeViewController* mailContainer = [listVues objectAtIndex:0];
UIView* mailView = [[[mailContainer view] subviews] objectAtIndex:0];
UIScrollView* composer = [[mailView subviews] objectAtIndex:0];
UIView* composerFields = [[composer subviews] objectAtIndex:0];
for (UIView* item in [composerFields subviews])
{
NSString* desc = [item description];
if ([desc hasPrefix:#"<MFMailComposeRecipientView"] == YES)
{
for (UIView* subitem in [item subviews])
{
NSString* desc2 = [subitem description];
if ([desc2 hasPrefix:#"<_MFMailRecipientTextField"] == YES)
{
UITextView* txt = (UITextView*)subitem;
}
}
}
else
if ([desc hasPrefix:#"MFComposeFromView"] == YES)
{
for (UIView* subitem in [item subviews])
{
NSString* desc2 = [subitem description];
if ([desc2 hasPrefix:#"<UITextField"] == YES)
{
UITextView* txt = (UITextView*)subitem;
}
}
}
else
if ([desc hasPrefix:#"<MFComposeSubjectView"] == YES)
{
// ...
}
else
if ([desc hasPrefix:#"<MFComposeMultiView"] == YES)
{
// ...
}
}
Change one of the four " if ([desc hasPrefix:#"..."] == YES) " content according to any needs.
You can save the [txt text] value to your own variable.