им с помощью этой строки кода, чтобы выполнить SEGUEпроблема с performSegueWithIdentifier и RootViewController
[self.window.rootViewController performSegueWithIdentifier:@"viewMessage" sender:self];
, но так как я зову rootViewController
его попытки искать viewMessage
idenifier в моем loginViewController
, когда мне это нужно, чтобы быть ищет его в friendsListTableViewController
Я пробовал просто объявить [self performSegueWithIdentifier:@"viewMessage" sender:self];
, но у меня есть два @implementations
и self
продолжает распознаваться как JBSlidingTableViewCell1
, и поскольку его UITableView не распознает performSeguqWithIdentifier
, я пробовал [friendsListTableViewController performSegueWithIdentifier:@"viewMessage" sender:self];
, но все, что я получаю, это t hat performSegueWithIdentifier не является исключением этого класса, когда на самом деле это UIViewController ...
Im пытается воздержаться от публикации кода как можно больше, так как есть слишком много, но я просто хотел посмотреть, есть ли способ заставить performSeguqWithIdentifier
, чтобы указать на мою friendsListTableViewController
вместо моего loginViewController
//
// friendsListTableViewController.m
// @ME
//
// Created by Aaron Russell on 1/22/13.
// Copyright (c) 2013 Aaron Russell. All rights reserved.
//
#import "friendsListTableViewController.h"
#import "loginViewController.h"
#import "viewMessageViewController.h"
#import "MyClass.h"
#import "AFNetworking.h"
#import "CCAlertView.h"
#import "UIImageView+AFNetworking.h"
#import "QuartzCore/QuartzCore.h"
@implementation JBSlidingTableViewCell1
CLLocationManager *locationManager;
@synthesize bottomDrawer1 = _bottomDrawer1;
@synthesize topDrawer1 = topDrawer1;
@synthesize titleLabel1 = _titleLabel1;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)identifier {
self = [super initWithStyle:style reuseIdentifier:identifier];
if (nil != self) {
self.titleLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(8, 13, 304, 20)];
self.titleLabel1.font = [UIFont boldSystemFontOfSize:17];
self.titleLabel1.textColor = [UIColor blackColor];
self.titleLabel1.backgroundColor = [UIColor clearColor];
[self.topDrawer1 addSubview:self.titleLabel1];
_bottomDrawer1 = nil;
// Top drawer
self.topDrawer1 = [[UIView alloc] init];
self.topDrawer1.backgroundColor = [UIColor whiteColor];
[self.contentView addSubview:self.topDrawer1];
}
return self;
}
- (void)dealloc {
_bottomDrawer1 = nil;
topDrawer1 = nil;
_titleLabel1 = nil;
}
- (void)closeDrawer1 {
if (self.topDrawer1.hidden == YES) {
CATransition* animation = [CATransition animation];
animation.delegate = self;
animation.type = kCATransitionFromRight;
animation.subtype = kCATransitionFromRight;
animation.duration = 0.8f;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[self.contentView.layer addAnimation:animation forKey:nil];
self.contentView.hidden = NO;
self.bottomDrawer1.hidden = YES;
}
}
- (void)openDrawer1 {
self.topDrawer1 = [[UIView alloc] initWithFrame:self.bounds];
self.bottomDrawer1 = [[UIView alloc] initWithFrame:self.bounds];
[self bottomDrawerWillAppear1];
[self insertSubview:self.bottomDrawer1 belowSubview:self.contentView];
CATransition* animation = [CATransition animation];
animation.type = kCATransitionFromLeft;
animation.subtype = kCATransitionFromLeft;
animation.duration = 1.0f;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[self.contentView.layer addAnimation:animation forKey:nil];
self.topDrawer1.hidden = YES;
self.contentView.hidden = YES;
}
- (void)bottomDrawerDidDisappear1 {
// Can be overridden by subclasses.
}
- (void)bottomDrawerWillAppear1 {
UIButton *inviteToLocationBtn=[UIButton buttonWithType:UIBarButtonSystemItemCompose];
inviteToLocationBtn.frame=CGRectMake(-40, -3, 150, 85);
[inviteToLocationBtn setBackgroundImage:[UIImage imageNamed:@"invite.png"]
forState:UIControlStateNormal];
[inviteToLocationBtn addTarget:self action:@selector(callInvite) forControlEvents:UIControlEventTouchUpInside];
[self.bottomDrawer1 addSubview:inviteToLocationBtn];
UIButton *findBtn=[UIButton buttonWithType:UIBarButtonSystemItemCompose];
findBtn.frame=CGRectMake(75, -3, 142, 85);
[findBtn setBackgroundImage:[UIImage imageNamed:@"find.png"]
forState:UIControlStateNormal];
[findBtn addTarget:self action:@selector(callFind) forControlEvents:UIControlEventTouchUpInside];
[self.bottomDrawer1 addSubview:findBtn];
UIButton *messageBtn=[UIButton buttonWithType:UIBarButtonSystemItemCompose];
messageBtn.frame=CGRectMake(180, -3, 190, 85);
[messageBtn setBackgroundImage:[UIImage imageNamed:@"message.png"]
forState:UIControlStateNormal];
[messageBtn addTarget:self action:@selector(callChat) forControlEvents:UIControlEventTouchUpInside];
[self.bottomDrawer1 addSubview:messageBtn];
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
[locationManager stopUpdatingLocation];
NSString *userurl = [NSString stringWithFormat: @"http://mysite.com/invitegps.php?latitude=%@&longitude=%@&email=%@&friend=%@", [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude], [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude], [MyClass str], [MyClass temail]];
NSURL *url = [NSURL URLWithString:userurl];
NSURLRequest *theRequest=[NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:userurl delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Failure to Connect." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
}
}
}
- (void)callInvite {
//TAKEN OUT FOR SIMPLICITY SAKE
}
- (void)callFind {
//TAKEN OUT FOR SIMPLICITY SAKE
}
- (void)callChat {
[self.window.rootViewController performSegueWithIdentifier:@"viewMessage" sender:self];
}
- (void)acceptLocationInvite {
}
- (void)declineLocationInvite {
}
- (void)acceptLocationRequest {
}
- (void)declineLocationRequest {
}
- (void)sendInstantMessage {
}
- (void)layoutSubviews {
[super layoutSubviews];
self.topDrawer1.frame = self.contentView.bounds;
}
- (void)animationDidStop:(CAAnimation*)anim finished:(BOOL)flag {
[self bottomDrawerDidDisappear1];
[self.bottomDrawer1 removeFromSuperview];
self.bottomDrawer1 = nil;
}
@end
@interface friendsListTableViewController();
@property (nonatomic, readonly) JBSlidingTableViewCell1* openedCell;
@property (nonatomic, retain) NSIndexPath* openedCellIndexPath;
@property (nonatomic, copy) NSArray* regularCellStrings;
- (void)closeOpenedCell;
@end
@implementation friendsListTableViewController
@synthesize openedCellIndexPath = _openedCellIndexPath;
@synthesize regularCellStrings = _regularCellStrings;
@synthesize tableView = _tableView;
@synthesize friends, friendList;
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"viewMessage"])
{
viewMessageViewController *dvController = segue.destinationViewController;
dvController.email = [MyClass temail];
[self presentViewController:dvController animated:YES completion:nil];
}
}
- (id)initWithCoder:(NSCoder*)aDecoder {
self = [super initWithCoder:aDecoder];
if (nil != self) {
_openedCellIndexPath = nil;
self.regularCellStrings = [NSArray arrayWithObjects:@"First default cell", @"Second default cell", nil];
}
return self;
}
- (void)dealloc {
_openedCellIndexPath = nil;
tableView = nil;
}
- (JBSlidingTableViewCell1*)openedCell {
JBSlidingTableViewCell1* cell;
if (nil == self.openedCellIndexPath) {
cell = nil;
} else {
cell = (JBSlidingTableViewCell1*)[self.tableView cellForRowAtIndexPath:self.openedCellIndexPath];
}
return cell;
}
- (void)closeOpenedCell {
[(JBSlidingTableViewCell1*)[self.tableView cellForRowAtIndexPath:self.openedCellIndexPath] closeDrawer1];
self.openedCellIndexPath = nil;
}
- (void)scrollViewWillBeginDragging:(UIScrollView*)scrollView {
[self closeOpenedCell];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {
return 1;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewDidLoad {
locationManager = [[CLLocationManager alloc] init];
[super viewDidLoad];
[self.tableView setDelegate:self];
[self.tableView setDataSource:self];
friendList = [[NSMutableArray alloc] initWithCapacity:0];
NSString *someOtherString = [NSString stringWithFormat: @"http://atmeapp.com/friendlist.php?userid=%@", [MyClass str]];
NSData *xmlData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:someOtherString]];
tbxml = [[TBXML alloc]initWithXMLData:xmlData];
TBXMLElement * root = tbxml.rootXMLElement;
if (root)
{
TBXMLElement * allFriends = [TBXML childElementNamed:@"friend" parentElement:root];
while (allFriends !=nil)
{
TBXMLElement * friendid = [TBXML childElementNamed:@"friendid" parentElement:allFriends];
NSString *fid = [TBXML textForElement:friendid];
TBXMLElement * fname = [TBXML childElementNamed:@"fname" parentElement:allFriends];
NSString *firstName = [TBXML textForElement:fname];
TBXMLElement * lname = [TBXML childElementNamed:@"lname" parentElement:allFriends];
NSString *lastName = [TBXML textForElement:lname];
NSString *fullname = [NSString stringWithFormat:@"%@ %@:%@", firstName, lastName, fid];
[friendList addObject:fullname];
allFriends = [TBXML nextSiblingNamed:@"friend" searchFromElement:allFriends];
}
//TBXMLElement *fname = [TBXML childElementNamed:@"fname" parentElement:elem_PLANT];
}
}
#pragma mark - UITableViewDelegate + UITableViewDatasource
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
return [friendList count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell* cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (nil == cell) {
cell = [[[JBSlidingTableViewCell1 alloc] init] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
friendsFullNames = (UILabel *)[cell viewWithTag:12];
NSArray *myWords = [[friendList objectAtIndex:indexPath.row] componentsSeparatedByString:@":"];
friendsFullNames.text = myWords[0];
NSLog(myWords[1]);
UIImageView *bgImageFile = (UIImageView *)[cell viewWithTag:21];
UIImageView *imageFile = (UIImageView *)[cell viewWithTag:13];
NSString *friendAvatar = [NSString stringWithFormat:@"%@%@%@", @"http://www.atmeapp.com/images/users/", myWords[1], @".jpg"];
[imageFile setImageWithURL:[NSURL URLWithString:friendAvatar]];
[bgImageFile setImageWithURL:[NSURL URLWithString:friendAvatar]];
//imageFile = [NSString stringWithFormat:@"%d", NUMBER_OF_ROWS - indexPath.row];
//cell.textLabel.text = [friendList objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
[self closeOpenedCell];
[(JBSlidingTableViewCell1*)[self.tableView cellForRowAtIndexPath:indexPath] openDrawer1];
NSArray *myWords = [[friendList objectAtIndex:indexPath.row] componentsSeparatedByString:@":"];
[MyClass settemail:myWords[1]];
NSLog(@"%@", myWords[1]);
self.openedCellIndexPath = indexPath;
}
- (IBAction)inviteAFriend:(id)sender {
NSString *userurl = [NSString stringWithFormat: @"http://atmeapp.com/friendreq.php?userid=%@&friendid=%@", [MyClass str], eMailTextField.text];
NSURL *url = [NSURL URLWithString:userurl];
NSURLRequest *theRequest=[NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:userurl delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Fail" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
}
}
- (void)inviteFriend:(id)sender {
}
- (void)declineFriendRequest {
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
#pragma mark - Table view delegate
- (IBAction)inviteFriends:(id)sender {
if ([MFMailComposeViewController canSendMail]){
// Email Subject
NSString *emailTitle = @"You have been invited to @ME!";
// Email Content
NSString *messageBody = @"<h2> Try @Me </h2> <br /><br /> <p>Beta is finally ready! Please visit link below, Beta is NOT available in the App Store yet. <br /> <br /> <a href='http://www.atmeapp.com/download.php'> Get @ME Now! </a> <br /> <br /> Brought to you by <a href='http://www.teknologenie.com> TeknoloGenie </a> </p>";
// To address
NSArray *toRecipents = [NSArray arrayWithObject:@"[email protected]"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:YES];
[mc setToRecipients:toRecipents];
// Present mail view controller on screen
[self presentViewController:mc animated:YES completion:NULL];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Account Found" message:@"You need to add an email account to your device" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
// optional - add more buttons:
[alert addButtonWithTitle:@"Add Account"];
[alert show];
}
}
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail sent failure: %@", [error localizedDescription]);
break;
default:
break;
}
// Close the Mail Interface
[self dismissViewControllerAnimated:YES completion:NULL];
}
@end
performSegueWithIdentifier должен вызываться (на себе) изнутри контроллера вида, который является контроллером представления исходного кода в режиме segue. Вы можете вызвать его с другого контроллера, но для его вызова вам понадобится ссылка на контроллер представления источника. Непонятно, что вы пытаетесь сделать здесь. – rdelmar
Я не могу называть себя, потому что у меня есть более одного @implementation в том же классе. Я должен был сделать это, чтобы открыть sliderDrawer. В основном мой UITableView содержит список друзей, я прокручиваю по ячейке, и появляется 3 кнопки, одна из этих кнопок - кнопка сообщения, которая, когда я прикасаюсь к ней, вызывает 'callChat' void, то есть внутри' @implementation JBSlidingTableViewCell1' внутри 'callChat', где я пытаюсь выполнить segue, im не совсем уверен, как объяснить это дальше, если вы хотите, чтобы я мог опубликовать весь код ... –
Я предполагаю, что segue подключается непосредственно к контроллеру вида, friendsListTableViewController? Вам нужно получить ссылку на этот контроллер из вашей реализации JBSlidingTableViewCell1. Я не уверен, как это сделать, поскольку я не знаю структуру вашего приложения. Является ли thisJBSlidingTableViewCell1 частью внешней структуры, которую вы используете? – rdelmar