lundi 1 décembre 2014

Programmatically create an object under different screen sizes

I am having the code below for creating an button.

Now the location of the button cannot be aligned or scaled correctly with different devices.


I wrote the following code under iPhone 6 screen size.



UIButton *but= [UIButton buttonWithType:UIButtonTypeRoundedRect];
[but addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[but setFrame:CGRectMake(605, 320, 35, 35)];
[but setTitle:@"Login" forState:UIControlStateNormal];
[but setExclusiveTouch:YES];
[self.view addSubview:but];


If i want to have the same position for iPhone 6 plus as the iPhone 6. What can i do?


Many thanks.




IOS Segue is not working in Custom Tab bar

i make my custom tab bar using segue it's run successfully , now i try to pass data between two view controller which is on tab bar view controller , i took total 4 view controller for custom tab bar view controller.but i am not getting button click event on this 4 view controller for open new view controller OR passing data between this 4 view controller.


my code for tab bar controller



- (void) perform {

ViewController *ctbcv = (ViewController *)self.sourceViewController;
UIViewController *dst = (UIViewController *) self.destinationViewController;
for(UIView *view in ctbcv.placeholder.subviews)
{
[view removeFromSuperview];
}
ctbcv.currentViewController = dst;
[ctbcv.placeholder addSubview:dst.view];
}


and segue condition



-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"HomeSegue"]
|| [segue.identifier isEqualToString:@"DeveloperSegue"]
|| [segue.identifier isEqualToString:@"DesignerSegue"]|| [segue.identifier isEqualToString:@"btn4"]){

NSLog(@"%lu",(unsigned long)[self.buttons.subviews count]);

for (int i=0; i<[self.buttons.subviews count];i++) {
UIButton *button = (UIButton *)[self.buttons.subviews objectAtIndex:i];
[button setSelected:NO];
}

UIButton *button = (UIButton *)sender;
NSLog(@"%ld", (long)button.tag);
btnclicked = button.tag;
[button setSelected:YES];
}
}


this code run successfully, now i create button on 1st view controller and give segue to the new view controller , it's crash when click on button.



- (void)viewDidLoad {
[super viewDidLoad];

[btnnext addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];

}

-(void) buttonClicked:(UIButton*)sender
{

NSLog(@"you clicked on button %ld", (long)sender.tag);

[self performSegueWithIdentifier:@"MySegue" sender:sender];

}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"MySegue"]) {
navVC *vc = [segue destinationViewController];

}
}


After this code it crash and Xcode show "THREAD 1: EXC_BAD_ACCESS(code=2 , address = 0xc)" any solution ?


i use this reference for making custom tab bar = http://ift.tt/1r2r7XX


i make button which open new view controller in this tab bar.


Thank You




How to set Animation Segue Style In Xib File like as StoryBoard Segue Style in iOS?

i am newbie in iOS Development i want to make an animation Style with Animation in Xib file.It is Possible?If it was Possible then please Give me Solution For that i Write a Segue For Xib like as



- (IBAction)pushMyNewViewController
{
MyNewViewController *myNewVC = [[MyNewViewController alloc] init];
[self presentModalViewController:myNewVC animated:YES];
}


It is Working But i want an animation Style like as StoryBoard Segue Style Cover Vertical,Flip Horizontal,Cross Dissolve Transition Style.




ios 8 uitableview stuck/hang/freeze when scrolling to the end of table

I really need helps from you. I'm trying to load some data (about 50 records) to UITableView. But it got frozen/hang while scrolling to the end of the tableview. I did try to log which row is displaying. When I scroll down, the log show the row 1... 49 is display then it starts over with row 42.


This is the .h file:



@interface VDevicesViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
{
NSString* access_token;
NSMutableArray* data;
NSMutableArray* deviceNotGoodData;
NSArray* _deviceTypeList;
NSArray* _thumnailArray;
DAPagesContainer* pageContainter;
UITableView* tableAllDevices;
UITableView* tableNotGoodDevices;

int currentPage;
UIView * footerView;
UIActivityIndicatorView* indicator;
}
@property (strong, nonatomic) IBOutlet UIView *myView;

-(void)refresh;
@end


this is the .m file



- (void)viewDidLoad
{
[super viewDidLoad];
CGRect screenRect = [[UIScreen mainScreen] bounds];
[self.myView setFrame:CGRectMake(0, 32, screenRect.size.width, screenRect.size.height)];

// Do any additional setup after loading the view
data = [[NSMutableArray alloc] init];
deviceNotGoodData = [[NSMutableArray alloc] init];
pageContainter = [[DAPagesContainer alloc] init];
[pageContainter setPageIndicatorImage:[UIImage imageNamed:@"up_arrow_gray"]];
[pageContainter setTopBarBackgroundColor:[UIColor colorWithRed:24.0f/255.0f green:177.0f/255.0f blue:214.0f/255.0f alpha:1]];
pageContainter.pageItemsTitleColor = [UIColor whiteColor];

[pageContainter willMoveToParentViewController:self];
pageContainter.view.frame = self.myView.bounds;
pageContainter.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
CGFloat width = self.myView.frame.size.width;
CGFloat height = self.myView.frame.size.height - 50;
CGRect tableFrame = CGRectMake(0, 0, width, height);
UIViewController* allDeviceContoler = [[UIViewController alloc] init];
tableAllDevices = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStylePlain];
tableAllDevices.delegate = self;
tableAllDevices.dataSource = self;
tableAllDevices.tag = 0;

NSString* allDeviceTitle = [NSString stringWithFormat:@"All Devices(%@)", [[NSUserDefaults standardUserDefaults] valueForKey:KEY_DEVICES_USED]];
allDeviceContoler.title = allDeviceTitle;
[allDeviceContoler.view addSubview:tableAllDevices];

UIViewController *notGoodDevicesControler = [[UIViewController alloc] init];
tableNotGoodDevices = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStylePlain];
tableNotGoodDevices.delegate = self;
tableNotGoodDevices.dataSource = self;
tableNotGoodDevices.tag = 1;

NSString* uncompliantDevices = [NSString stringWithFormat:@"With Issues(%@)", [[NSUserDefaults standardUserDefaults] valueForKey:KEY_DEVICES_UNCOMPLIANT]];
notGoodDevicesControler.title = uncompliantDevices;
[notGoodDevicesControler.view addSubview:tableNotGoodDevices];

[self.myView addSubview:pageContainter.view];
[pageContainter didMoveToParentViewController:self];
pageContainter.viewControllers = @[allDeviceContoler, notGoodDevicesControler];
currentPage = 1;
access_token = [[NSUserDefaults standardUserDefaults] valueForKey:TOKEN_ACCESS_KEY];
_deviceTypeList = [NSArray arrayWithObjects:@"desktop", @"laptop", @"phone", @"tablet", @"server", @"router", @"switch", @"vm", nil];

_thumnailArray = [NSArray arrayWithObjects:@"device_desktop_small", @"device_laptop_small", @"phone", @"tablet", @"device_server_small", @"router", @"switch", @"device_vm_small", nil];

[self GetDevices:[NSNumber numberWithInt:currentPage]];
indicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(screenRect.size.width/2.0, 40, 37, 37)];
[indicator startAnimating];

[self.myView addSubview:indicator];
}

#pragma mark - TableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView.tag == 0) {
return [data count];
}
else if (tableView.tag == 1)
return [deviceNotGoodData count];
return 0;
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString* cellIdentitifier = @"TableCell";
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIdentitifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentitifier];

}

NSArray* flexData;
if (tableView.tag == 0) {
flexData = [NSArray arrayWithArray:data];
}
else
flexData = [NSArray arrayWithArray:deviceNotGoodData];


if (flexData.count > 0) {
if (indexPath.row < ([flexData count])) {
// add data here
NSLog(@"%ld", (long)indexPath.row);
VDeviceObject * deviceObject = [flexData objectAtIndex:(indexPath.row)];
cell.textLabel.text = deviceObject.hostname;
cell.detailTextLabel.text = deviceObject.username;
cell.detailTextLabel.textColor = [UIColor colorWithRed:180.0f/255.0f green:180.0f/255.0f blue:180.0f/255.0f alpha:1];

if ([deviceObject.numberOfIssues intValue] > 0) {
cell.backgroundColor = [UIColor colorWithRed:247.0f/255.0f green:247.0f/255.0f blue:247.0f/255.0f alpha:1];
}

cell.imageView.image = [UIImage imageNamed:[_thumnailArray objectAtIndex:[deviceObject.deviceType intValue]]];
}
}

return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier: @"ViewDetail" sender:indexPath];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 65;
}
-(void)GetDevices:(NSNumber*)page {
if (access_token == nil || [access_token isEqualToString:@""]) {
return;
}
NSError* error;
NSData * devicesData = [VTabBarViewController sendSyncGetRequest:[NSString stringWithFormat:@"%@?access_token=%@&limit=%@&GroupBy=issues&page=%@", GEARS_API_GET_DEVICES, access_token, @"50", page] errorCode:error];

NSString* errorString = [[NSString alloc] initWithData:devicesData encoding:NSUTF8StringEncoding];
NSString* stringCode = @"Requested page number exceeds limit";
if ([errorString rangeOfString:stringCode].location != NSNotFound) {
return;
}
NSMutableArray* list = [NSJSONSerialization JSONObjectWithData:devicesData options:NSJSONReadingAllowFragments error:&error];
for (int i = 0 ; i<[list count]; ++i) {
NSDictionary *dict = [list objectAtIndex:i];
NSString* hostName = [dict objectForKey:@"hostname"];
NSString *machine_type = [dict objectForKey:KEY_MACHINE_TYPE];
NSNumber* numberIssues = [dict objectForKey:KEY_TOTAL_ISSUE];
NSDictionary *userinfo = [dict objectForKey:KEY_USER_INFO];
NSString* username = [userinfo objectForKey:KEY_USER_NAME];
NSString* hwid = [dict objectForKey:KEY_HWID];
VDeviceObject *object = [[VDeviceObject alloc] init];
object.username = username;
object.deviceType = [self deviceType:machine_type];
object.numberOfIssues = numberIssues;
object.hostname = hostName;
object.hardwareId = hwid;

[data addObject:object];
if ([object.numberOfIssues intValue] > 0) {
[deviceNotGoodData addObject:object];
}
}
NSLog(@"On page: %d", currentPage);
//[tableAllDevices reloadData];
//[tableNotGoodDevices reloadData];
}


This is the gif image to demonstrate the problem I've got (I did try to reduce the size but its quality is so bad) http://ift.tt/1zBy4Co


Thank you...


Update: I try to add 'UITableView' by storyboard, connect with the 'IBOutlet', it works. So maybe I did something wrong with the table :(




Is it possible to have 2 Tab bars in an iOS appliction

I am developing an iphone app , in which i have one root Tab bar with 4 tab bar items which will be at top of screen. and in one Tab bar item i again need to display another Tab bar which will be at bottom.


So is it possible ?




iOS8/Swift Data Persistence after uninstall

I'm developing an iPhone application for iOS8 in Swift. I currently save all the user data through NSUserDefaults and this works completely fine. Once I uninstall the demo app from my phone and reinstall it through XCode6, all the NSUserDefaults are gone, this is expected.


Question: How do I persist user data after uninstall?




ios app flow is missing view Controller in Flow. Xcode 6.1

Following is my application flow.


Flow 1) app Delegate - app login page(signup) -> Form View to -> welcome screen (on ok) -> Dashboard/User home page.


Flow 2) app Delegate - app login page(login) -> Dashboard/User home page.


I unchecked "Use Size Classes" from "File Inspector". I am not using autolayout. I am using different storyboard for different device like iPhone 6 , iPhone 6plus , iPhone 5s, iPhone 4s.


Now each time I'm checking the device, the app is running and loading the specific storyboard.


The app is running fine for only one iphone 6 plus device and iphone 4s,5s simulator.


But when I installed and tested it on multiple devices (all 4s,5s,6, another 6s device ) it is not loading the dashboard on welcome screen (on ok) in first Flow 1. and also on successful login in Flow 2.


All the devices having ios 8 and above.


I debugged the flow through code step by step. But it is following the right logical path.


Please if you have any solution help me with this situation. any suggestions are really appreciated.


Thanks,