我正在使用这行代码来执行segue
[self.window.rootViewController performSegueWithIdentifier:@"viewMessage" sender:self];
但是因为我正在呼叫rootViewController
当我需要在viewMessage
中寻找loginViewController
friendsListTableViewController
时,我试图在[self performSegueWithIdentifier:@"viewMessage" sender:self];
中寻找@implementations
标识符声明self
,但我有两个JBSlidingTableViewCell1
和performSeguqWithIdentifier
一直认为是[friendsListTableViewController performSegueWithIdentifier:@"viewMessage" sender:self];
,因为它是一个UITableView,它无法识别performSeguqWithIdentifier
我试过friendsListTableViewController
但我得到的是performSegueWithIdentifier不是该类的一部分,实际上它是一个UIViewController ......
我试图尽量避免发布代码,因为它有很多,但我只是想看看是否有办法强迫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:@"aaron@teknologenie.com"];
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
而不是我的{{1}}
{{1}}
答案 0 :(得分:1)
鉴于您的应用程序的结构,似乎获取对friendsListTableViewController的引用的唯一方法是查找视图链。因为,nextResponder方法将返回它负责的视图的视图控制器,以下应该从自定义单元的实现文件中获取对所需视图控制器的引用:
self.superview.superview.nextResponder
在这种情况下,单元格的超级视图是表格视图,并且该表格视图位于控制器主视图的子视图中,因此self.superview.superview将您带到控制器的self.view。 nextResponder的文档说:“UIView通过返回管理它的UIViewController对象(如果有的话)来实现这个方法”。因此,在控制器的self.view上调用nextResponder会为您提供控制器。