我的.h文件如下所示
#import <UIKit/UIKit.h>
#import "ScrollTestViewController.h" @interface EliteScreen : UIViewController
- (IBAction)eliteII_BtnClk:(id)sender;
@end
我的.m文件如下所示
#import "EliteScreen.h"
#import "EliteQuestionScreen.h"
#import "NextView.h"
#import "ScrollTestViewController.h"
@interface EliteScreen ()
@end
@implementation EliteScreen{
NSArray *viewArray;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)eliteII_BtnClk:(id)sender {
ScrollTestViewController* optimztionscreen1 = [[ScrollTestViewController alloc]
initWithNibName:@"ScrollTestViewController" bundle:[NSBundle mainBundle]];
NSLog(@"ahbjcdcx");
[[self navigationController] pushViewController:optimztionscreen1 animated:YES];
}
@end
我的ScrollTestViewController.h如下所示
#import <UIKit/UIKit.h>
#import "EliteQuestionScreen.h"
@interface ScrollTestViewController : UIViewController
@property(strong,nonatomic)EliteQuestionScreen *opt;
@end
我的ScrollTestViewController.m如下所示
#import "ScrollTestViewController.h"
#import "EliteQuestionScreen.h"
@interface ScrollTestViewController ()
@end
@implementation ScrollTestViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self addSubViewToScrollView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)addSubViewToScrollView{
CGFloat x = 0;
UIScrollView *scrollview = [[UIScrollView alloc]
initWithFrame:CGRectMake(0, 0,
self.view.frame.size.width, self.view.frame.size.height)];
NSInteger viewcount= 8;
for(int i = 0; i< viewcount; i++) {
// EliteQuestionScreen* optimztionscreen = [[EliteQuestionScreen alloc]
initWithNibName:@"EliteQuestionScreen" bundle:[NSBundle mainBundle]];
self.opt = [[EliteQuestionScreen alloc]
initWithNibName:@"EliteQuestionScreen"
bundle:[NSBundle mainBundle]];
if (i == 0) {
x = self.opt.view.frame.origin.x;
} else {
x = self.opt.view.frame.size.width + x;
}
NSLog(@"I %d",i);
UIView *viewMine = self.opt.view;
viewMine.frame = CGRectMake(x, 0, self.opt.view.frame.size.width,
self.opt.view.frame.size.height);
[scrollview setPagingEnabled:YES];
[scrollview addSubview:viewMine];
}
scrollview.contentSize = CGSizeMake(self.view.frame.size.width *viewcount,
self.view.frame.size.height);
[self.view addSubview:scrollview];
NSLog(@"MY VALUE FOR X %f",self.view.frame.size.width *viewcount);
}
@end
我的eliteQuestionscreen.h文件如下
#import <UIKit/UIKit.h>
@interface EliteQuestionScreen : UIViewController <UITableViewDelegate,
UITableViewDataSource>
{
UITableView *tableview;
}
@property (nonatomic, assign) UIEdgeInsets edgeInsets;
- (IBAction)noBtn:(id)sender;
@end
我的EliteScreenQuestion.m文件如下
#import "EliteQuestionScreen.h"
#import "AppConstant.h"
#import "SimpleTableCell.h"
#import "PopUpController.h"
#import "AssetPopUpController.h"
#import "BrowseProgrammingTools.h"
#import "NextView.h"
@interface EliteQuestionScreen ()
@end
@implementation EliteQuestionScreen
{
NSArray *tableData;
NSArray *thumbnails;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self setFontOnText];
tableData = [NSArray arrayWithObjects:first_screen_firstBtn_title,
first_screen_secondBtn_title,first_screen_thirdBtn_title, nil];
thumbnails = [NSArray arrayWithObjects:@"assetImage_iPad.png",
@"assetImage_iPad.png",
@"assetImage_iPad.png",nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:
(NSInteger)section
{
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableCell";
SimpleTableCell *cell = (SimpleTableCell *)[tableView
dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell"
owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.nameLabel.text = [tableData objectAtIndex:indexPath.row];
cell.thumbnailImageView.image = [UIImage imageNamed:[thumbnails
objectAtIndex:indexPath.row]];
[cell.nameLabel setFont:[UIFont fontWithName:@"UniversLTStd-BoldCn" size:13.00f]];
[cell.nameLabel sizeToFit];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath{
SimpleTableCell *newCell = (SimpleTableCell*)[tableView
cellForRowAtIndexPath:indexPath];
NSString *Abc = newCell.nameLabel.text;
NSLog(@"MY TIME %@",Abc);
AssetPopUpController* optimztionscreen = [[AssetPopUpController alloc]
initWithNibName:@"AssetPopUpController" bundle:[NSBundle mainBundle]];
[self.navigationController presentViewController:optimztionscreen animated:NO
completion:nil];
optimztionscreen.assetTitle.text = Abc;
[optimztionscreen.assetTitle setFont:[UIFont fontWithName:@"UniversLTStd-BoldCn"
size:20.00f]];
[optimztionscreen.assetTitle sizeToFit];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath
*)indexPath
{
return 65;
}
-(void)setFontOnText{
}
- (IBAction)noBtn:(id)sender {
[self createTableViewForNO];
}
-(void) createTableViewForNO{
tableview=[[UITableView alloc]init];
tableview.frame = CGRectMake(555,456,149,269);
tableview.dataSource=self;
tableview.delegate=self;
[tableview registerClass:[SimpleTableCell class]
forCellReuseIdentifier:@"SimpleTableCell"];
[tableview reloadData];
[self.view addSubview:tableview];
}
@end
每当我在EliteQuestionScreen应用程序中没有按钮点击时,崩溃错误是
[EliteQuestionScreen performSelector:withObject:withObject:]: message sent to deallocated instance 0x7586c60
答案 0 :(得分:0)
在ScrollTestViewController.m
你做:
self.opt = [[EliteQuestionScreen alloc]
initWithNibName:@"EliteQuestionScreen"
bundle:[NSBundle mainBundle]];
查看次数。
除了最后一个之外的所有内容都将被释放。最后一个保留在self.opt中。如果你试图引用其他的那些,你就会崩溃。
这里没有简单的解决方法。您正尝试将UIViewController
笔尖用于其视图,这不是一个好方法。仔细查看代码,我认为您可能需要重新考虑您的架构。例如,您可能希望切换到UITableView
或UICollectionView
,而不是加载此视图控制器n次。