UIViewController custom init method does not show - ios

I have seen how to create your own custom init method I have one that looks like this
- (id)initWithArray:(NSArray *)array
{
if ((self = [super init])) {
currentArray = array;
NSLog(#"%#", currentArray);
}
return self;
}
however when I try to call it i can never see initWithArray this is the way I call it.
if (![pictureViewController.view superview]) {
pictureViewController= [[PictureViewController alloc] init];
pictureViewController.stackRotationController = stackRotationController;
[pictureViewController ini = pluginsMutableArray]; // cannot see initWithArray
[pictureViewController.view setBackgroundColor:[UIColor whiteColor]];
pictureViewController.view.frame = CGRectMake(0.0, ScreenHeight, ScreenWidth, ScreenHeight);
pictureViewController.prefToolBar.frame = CGRectMake(0.0, 0.0, ScreenWidth, 45.0);
[pictureViewController.view addSubview:pictureViewController.prefToolBar];
[[UIToolbar appeara}nce] setBarTintColor:[UIColor colorWithRed:colorController.oRed/255.0 green:colorController.oGreen/255.0 blue:colorController.oBlue/255.0 alpha:1.0]];

Related

animation not works in the non-initial UIViewController

I have a UIView called loadingView shows some UIActivityIndicatorView-like animation. There are two UIViewControllers that all have such UIView.
The initial UIViewController's code:
- (void)viewDidLoad {
self.loadingView = [[LoadingView alloc] initWithFrame:CGRectMake(10, 1, 120, 120)];
[self.view addSubview:self.loadingView];
}
Also it has a button to present the second UIViewController:
- (void)buttonPressed {
SecondViewController *sVC = [[SecondViewController alloc] init];
[self presentViewController:sVC animated:YES completion:nil];
}
The second ViewController's viewDidLoad method code:
- (void)viewDidLoad {
self.loadingView = [[LoadingView alloc] initWithFrame:CGRectMake(10, 1, 120, 120)];
[self.view addSubview:self.loadingView];
}
As you can see, the two UIViewControllers has the same viewDidLoad method code.
The loadingView works well in the initial UIViewController.
But in the second UIViewController, the loadingView only displays the black frame( I set the background colour to black).
Here is my loadingView implement code:
#define NUMBER_OF_DOT 15
#define DURATION 1.5
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.replicatorLayer = [[CAReplicatorLayer alloc] init];
self.replicatorLayer.frame = frame;
self.replicatorLayer.cornerRadius = 10.0;
self.replicatorLayer.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.86].CGColor;
self.replicatorLayer.position = self.center;
self.replicatorLayer.instanceDelay = DURATION/NUMBER_OF_DOT;
[self.layer addSublayer:self.replicatorLayer];
float size = frame.size.width*14/200;
self.dot = [[CALayer alloc] init];
self.dot.bounds = CGRectMake(0, 0, size, size);
self.dot.position = CGPointMake(frame.size.width/2, frame.size.height/5);
self.dot.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1.0].CGColor;
self.dot.borderColor = [UIColor whiteColor].CGColor;
self.dot.borderWidth = 1.0;
self.dot.cornerRadius = 1.5;
self.dot.transform = CATransform3DMakeScale(0.01, 0.01, 0.01);
[self.replicatorLayer addSublayer:self.dot];
self.replicatorLayer.instanceCount = NUMBER_OF_DOT;
float angle = 2*M_PI/NUMBER_OF_DOT;
self.replicatorLayer.instanceTransform = CATransform3DMakeRotation(angle, 0.0, 0.0, 0.1);
self.shrink = [[CABasicAnimation alloc] init];
self.shrink.keyPath = #"transform.scale";
self.shrink.fromValue = [NSNumber numberWithFloat:1.0];
self.shrink.toValue = [NSNumber numberWithFloat:0.1];
self.shrink.duration = DURATION;
self.shrink.repeatCount = INFINITY;
[self.dot addAnimation:self.shrink forKey:nil];
}
return self;
}
-(void)viewDidAppear:(BOOL)animated
{
self.loadingView = [[LoadingView alloc] initWithFrame:CGRectMake(10, 1, 120, 120)];
[self.view addSubview:self.loadingView];
}
Put this code in viewDidAppear of SecondViewController so it works in present mode as well.

iOS 7 UITableView inside a popover

I have a UITableView which has some custom styling. This table view appears in two places in the app, one of which is inside a UIPopoverController. However when the tableview is inside the popover it takes on the default tableview styling as stated in the UI Transition Guide under "Popover".
The problem I have is that there appears to be nowhere to change this behaviour. Regardless of where I try and modify properties of the tableview the view inside the popover doesn't change.
Anyone dealt with this issue before or have any ideas?
Here is the init method of LibraryProductView where I create the table view:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.sectionOrdering = [NSArray arrayWithObjects:
[NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_DESCRIPTION],
[NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_DOCUMENTS],
[NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_ACTIVE_INGREDIENTS],
[NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_RELATED_PRODUCTS],
[NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_RELATED_DOCUMENTS], nil];
self.backgroundColor = [UIColor whiteColor];
self.tableView = [[UITableView alloc] initWithFrame:CGRectInset(self.bounds, 10, 0) style:UITableViewStyleGrouped];
self.tableView.backgroundColor = [UIColor whiteColor];
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.separatorColor = [UIColor clearColor];
self.tableView.showsVerticalScrollIndicator = NO;
[self addSubview:self.tableView];
}
return self;
}
Here is where the containing view (LibraryProductView) is added to the popover:
- (IBAction)didTouchInformationButton:(id)sender
{
if (_infoPopover != nil && _infoPopover.isPopoverVisible)
{
[_infoPopover dismissPopoverAnimated:YES];
return;
}
CGSize preferredSize = CGSizeMake(600.0f, 500.0f);
LibraryProductViewController* productController = [[[LibraryProductViewController alloc] initWithPreferredSize:preferredSize] autorelease];
productController.filterByMyCompany = NO;
productController.product = _activityInput.product;
UINavigationController* nav = [[[UINavigationController alloc] initWithRootViewController:productController] autorelease];
nav.title = _activityInput.product.name;
RELEASE(_infoPopover);
_infoPopover = [[UIPopoverController alloc] initWithContentViewController:nav];
_infoPopover.popoverContentSize = CGSizeMake(preferredSize.width, preferredSize.height + 46);
[_infoPopover presentPopoverFromRect:_infoButton.frame inView:_infoButton permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}
The LibraryProductView is created within viewDidLoad method of LibraryProductViewController.
- (void)viewDidLoad
{
[super viewDidLoad];
self.libraryProductView = [[LibraryProductView alloc] initWithFrame:(usingPreferredSize ? CGRectMake(0.0, 0.0, preferredSize.width, preferredSize.height) : self.view.bounds)];
self.libraryProductView.dataSource = self;
self.libraryProductView.delegate = self;
[self.view addSubview:self.libraryProductView];
}
To set properties for the TableView you might do so in
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
[tableView setBackgroundColor:[UIColor redcolor]];
[tableView setSeparatorColor: [UIColor blueColor]];
return 1;
}
This, of course, assumes you have set UITableViewDataSource in your .h file

self.view.size in a custom view returns [0,0]

I have my custom view:
#interface MailAttributesView : UIView
{
...
#implementation MailAttributesView
{
UIView *_selectionView;
}
(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
DLog(#"frame.size.width -[%f]; frame.size.height -[%f] ",frame.size.width, frame.size.height);
}
return self;
}
-(void)awakeFromNib
{
[self initView];
}
-(void)initView
{
DLog(#"self.frame.size.width -[%f]; self.frame.size.height -[%f] ",self.frame.size.width, self.frame.size.height);
CGRect sectionSize = CGRectMake(0, 0 , self.frame.size.width, self.frame.size.height);
_selectionView = [[UIView alloc] initWithFrame:sectionSize];
[_selectionView setBackgroundColor:[UIColor clearColor]];
fromField = [[JSTokenField alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, ROW_HEIGHT)];
[[fromField label] setText:#" From:"];
[fromField setDelegate:self];
[_selectionView addSubview:fromField];
In my storyboard I've created a view and set it my custom view class. Problem that in my view I call self.view to define width of the view - but it always returns 0.
I can hardcore needed values - but I expect to get it working like standard controls work - I mean for example auto-sizing if rotate and so on.
What's my misunderstanding?
If you are adding the custom view in storyboards, you would not be using initWithFrame:
Instead use initWithCoder:
Try this:
- (id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder]) {
DLog(#"self.frame.size.width -[%f]; self.frame.size.height -[%f] ",self.frame.size.width, self.frame.size.height);
}
return self;
}

UITableViewCell subviews issue

I load cell from xib. I added 3 vertical separators to the cell (tried to add from xib and from code). Everything is OK until I select the cell. When I select the sell, separators disappear.
Here are the images:
Not selected:
Selected
Code of adding separators:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
self.topSeparator = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 1)] autorelease];
[self addSubview:topSeparator];
self.bottomSeparator = [[[UIView alloc] initWithFrame:CGRectMake(0, self.bounds.size.height - 1, self.bounds.size.width, 1)] autorelease];
[self addSubview:bottomSeparator];
// Initialization code
CGFloat xOffset = 314;
UIView *imageView1 = [[[UIView alloc] initWithFrame:CGRectMake(xOffset, 0, 1, self.bounds.size.height)] autorelease];
imageView1.tag = kTagBorder1;
imageView1.backgroundColor = [UIColor blackColor];
[self addSubview:imageView1];
xOffset = 487;
imageView1 = [[[UIView alloc] initWithFrame:CGRectMake(xOffset, 0, 1, self.bounds.size.height)] autorelease];
imageView1.tag = kTagBorder2;
imageView1.backgroundColor = [UIColor blackColor];
[self addSubview:imageView1];
xOffset = 573;
imageView1 = [[[UIView alloc] initWithFrame:CGRectMake(xOffset, 0, 1, self.bounds.size.height)] autorelease];
imageView1.tag = kTagBorder3;
imageView1.backgroundColor = [UIColor blackColor];
[self addSubview:imageView1];
}
return self;
}
I even tried this:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
[self bringSubviewToFront:[self viewWithTag:kTagBorder1]];
[self bringSubviewToFront:[self viewWithTag:kTagBorder2]];
[self bringSubviewToFront:[self viewWithTag:kTagBorder3]];
[self setNeedsDisplay];
// Configure the view for the selected state
}
You should not add the lines as a child view of self (UITableViewCell). Instead, add it as a child of self.contentView - which is the view containing the components inside a UITableViewCell.
This article contains tips on how to customize a UITableView properly.
I fixed it. I used UIImageView with black image instead of uiview with black background. In this case view doesn't disappear.

Hidding UILabel on Init

I'm having a problem with this basic code:
-(id)init{
self = [super init];
if(self){
self.mensaje = [[UILabel alloc]initWithFrame:CGRectMake(100.0, 100.0, 100.0, 100.0)];
[self.mensaje setText:#"He vuelto"];
[self.view addSubview:self.mensaje];
[self.mensaje setHidden:YES];
}
return self;
}
All the code works fine, except [self.mensaje setHidden:YES];. The Label is always shown at start.
I hope could help me, this is basic, but necessary!!
Good luck!
This code is in the wrong place. You shouldn't be creating and working with views in the initializer of a view controller (assuming the above code is inside a view controller class).
instead, do the following:
- (id)init
{
self = [super init];
if (self) {
// init any state other than views
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.mensaje = [[UILabel alloc] initWithFrame:CGRectMake(100.0, 100.0, 100.0, 100.0)];
[self.mensaje setText:#"He vuelto"];
[self.view addSubview:self.mensaje];
[self.mensaje setHidden:YES];
}
This also assumes you are using ARC. If not, you need to add autorelease as follows:
self.mensaje = [[[UILabel alloc] initWithFrame:CGRectMake(100.0, 100.0, 100.0, 100.0)] autorelease];

Resources