How to modal the view when network connecting - three20

Is there any way to set the view page modal during network connecting? I mean all controllers in page do not response the user operation if the network is connecting?
I updated code like:
- (void)loadView
{
[super loadView];
_hudView = [[UIView alloc] initWithFrame:CGRectMake(75, 155, 170, 170)];
_hudView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
_hudView.clipsToBounds = YES;
_hudView.layer.cornerRadius = 10.0;
_activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
_activityIndicatorView.frame = CGRectMake(65, 40, _activityIndicatorView.bounds.size.width, _activityIndicatorView.bounds.size.height);
[_hudView addSubview:_activityIndicatorView];
[_activityIndicatorView startAnimating];
_captionLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 115, 130, 22)];
_captionLabel.backgroundColor = [UIColor clearColor];
_captionLabel.textColor = [UIColor whiteColor];
_captionLabel.adjustsFontSizeToFitWidth = YES;
_captionLabel.textAlignment = UITextAlignmentCenter;
_captionLabel.text = #"Loading...";
[_hudView addSubview:_captionLabel];
NSArray *buttonNames = [NSArray arrayWithObjects:#"hehe",#"xixi",nil];
UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithItems:buttonNames];
segmentControl.frame = CGRectMake(0, 0, TTApplicationFrame().size.width/2, TT_ROW_HEIGHT-10);
segmentControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentControl.momentary = NO;
segmentControl.tintColor = [UIColor darkGrayColor];
segmentControl.selectedSegmentIndex = 0;
[segmentControl addTarget:self action:#selector(switchPage:) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = segmentControl;
TT_RELEASE_SAFELY(segmentControl);
self.view = [[[UIView alloc] initWithFrame:TTApplicationFrame()] autorelease];
self.tableView = [[[UITableView alloc] initWithFrame:TTApplicationFrame() style:UITableViewStylePlain] autorelease];
self.tableView.rowHeight = 80.f;
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:self.tableView];
[self reload];
[self updateView];
}
and show it like:
- (void)showLoading:(BOOL)show {
if (show) {
self.loadingView = _hudView;
}
else {
self.loadingView = nil;
}
}
As I said in comment, it still cannot cover the buttons of UISegmentedControl, user still can click those buttons...

Instead of using a modalViewController, create a HUD (one of the nice views with a UIActivityIndicators you'll see in the TTCatalogue app) that will block the view and inform the user something is happening while you're making a request.
Just insert them by a [self.view addSubview:theHUDview];.
It's not necessarily good design though, instead, make your network calls asynchronously, in the background.

Related

Adding UISegmentedControl to UIScrollView programmatically

I am tyring to add UISegmentedControl to UIScrolview programmatically.
I am using below code..
I don't why the scrollview is not enabled.
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 435)];
scroll.contentSize = CGSizeMake(320, 700);
scroll.showsHorizontalScrollIndicator = YES;
NSArray *menu = [NSArray arrayWithObjects:[UIImage imageNamed:#"Accountimg.png"],[UIImage imageNamed:#"Challengesimg.png"],[UIImage imageNamed:#"Profileimg.png"],[UIImage imageNamed:#"Challengesimg.png"],nil];
UISegmentedControl *menuSegmentedControl = [[UISegmentedControl alloc] initWithItems:menu];
menuSegmentedControl.frame = CGRectMake(0,0,450,40);
menuSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
[scroll addSubview:menuSegmentedControl];
[menuScrollView addSubview:scroll];
[menuSegmentedControl release];
[scroll release];
I am unable to scroll horizontally..
Thanks in advance
UPDATE:
I am able to get the horizontal scroll.
Code updated:
menuSegmentedControl.frame = CGRectMake(0,0,500,35);
menuSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
menuScrollView.contentSize = CGSizeMake(menuSegmentedControl.frame.size.width, menuSegmentedControl.frame.size.height);
menuScrollView.showsVerticalScrollIndicator = NO;
[menuScrollView addSubview:menuSegmentedControl];
menuScrollView.clipsToBounds = YES;
Thank you.

Uisegment buttons over scroll view

hi iam trying to put a uisegmented controls over a uiscrollview beacuse i want them to scroll horizontally this is the code i tried
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 600, 300)];
scroll.contentSize = CGSizeMake(500, 50);
scroll.showsHorizontalScrollIndicator = YES;
scroll.pagingEnabled = YES;
scroll.showsHorizontalScrollIndicator = YES;
scroll.autoresizingMask = YES;
scroll.autoresizesSubviews = YES;
NSArray *itemArray = [NSArray arrayWithObjects: #"One", #"Two", #"Three",#"four",#"Five", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
segmentedControl.frame = CGRectMake(0,10, 500, 50);
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
segmentedControl.selectedSegmentIndex = 4;
[scroll addSubview:segmentedControl];
[self.view addSubview:scroll];
any one please help me to accomplish this . thanks in advance happy coding
The frame for the scroll View must be less than the Content size of scroll view. If you will increase your content size definitely it will work. For example:-
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
scroll.contentSize = CGSizeMake(500, 50);
scroll.showsHorizontalScrollIndicator = YES;
scroll.pagingEnabled = YES;
scroll.showsHorizontalScrollIndicator = YES;
scroll.autoresizingMask = YES;
scroll.autoresizesSubviews = YES;
NSArray *itemArray = [NSArray arrayWithObjects: #"One", #"Two", #"Three",#"four",#"Five", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
segmentedControl.frame = CGRectMake(0,10, 500, 50);
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
segmentedControl.selectedSegmentIndex = 4;
[scroll addSubview:segmentedControl];
[self.view addSubview:scroll];
If its supportive please mark the answer correct. Thanks very much.

UIPickerController - want to show specific selection upon loading

I have a custom UIPickerView that is embedded into an UIActionsheet that comes up half the screen when called. Works great. The problem is that I want to have the barrelPicker be showing the 'most probable' results as the selection when it first comes up (after all the data has been loaded into it).
Prior to having the custom picker embedded in the action sheet, I had it in a UIViewController and was just calling "showProbableResults" (a custom method of mine) in the viewDidLoad method of the ViewController, because I knew at that point, the UIPickerView would be loaded up and ready to go. Is there an equivalent place for me to call this method now or do I need to rethink my whole design? Essentially, what I need is a place to call this after the UIPickerView has been loaded.
- (void)startWithDelegate:(UIViewController <ImageProcessingDelegate> *)sender
{
self.delegate = sender;
self.showFirstBottle = YES;
[self start];
}
- (void) start {
self.actionSheet = [[UIActionSheet alloc] initWithTitle:#"Choose Something"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[self.actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
NSLog(#"1.) About to alloc the picker");
self.vintagePicker = [[UIPickerView alloc] initWithFrame:pickerFrame];
self.vintagePicker.showsSelectionIndicator = YES;
self.vintagePicker.dataSource = self;
self.vintagePicker.delegate = self;
[self.actionSheet addSubview:self.vintagePicker];
[self.vintagePicker release];
UISegmentedControl *nextButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"Next"]];
nextButton.momentary = YES;
nextButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
nextButton.segmentedControlStyle = UISegmentedControlStyleBar;
nextButton.tintColor = [UIColor blackColor];
[nextButton addTarget:self action:#selector(show:) forControlEvents:UIControlEventValueChanged];
[self.actionSheet addSubview:nextButton];
[nextButton release];
UISegmentedControl *backButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"Back"]];
backButton.momentary = YES;
backButton.frame = CGRectMake(10, 7.0f, 50.0f, 30.0f);
backButton.segmentedControlStyle = UISegmentedControlStyleBar;
backButton.tintColor = [UIColor blackColor];
[backButton addTarget:self action:#selector(cancel:) forControlEvents:UIControlEventValueChanged];
[self.actionSheet addSubview:backButton];
[backButton release];
[self.actionSheet showInView:_delegate.parentViewController.tabBarController.view]; // show from our table view (pops up in the middle of the table)
[self.actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
}
One option is to create a reusable picker view, as shown here, and then call the #optional
-(void)setInitialPickerValueToRow:(int)i inComponent:(int)j animated:(BOOL)k{
[pickerView selectRow:i inComponent:j animated:k];
}
from any view controller or NSObject (such as your UIActionSheetDelegate).
Your other option is to set a standard pre-chosen selection, as follows:
self.vintagePicker = [[UIPickerView alloc] initWithFrame:pickerFrame];
self.vintagePicker.showsSelectionIndicator = YES;
self.vintagePicker.dataSource = self;
self.vintagePicker.delegate = self;
[self.actionSheet addSubview:self.vintagePicker];
[self.vintagePicker selectRow:0 inComponent:0 animated:NO];
You could also have different variables that you set, and have selectRow:inComponent:animated: access those, instead of being preset.
[self.vintagePicker selectRow:myRow inComponent:0 animated:NO];
Hope this helps!

How to put programmatically iCarousel in View?

I want four ScrollViews like iCarousel's CoverFlow in View programmatically. My Code is
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
//set up data
wrap = YES;
self.items = [NSMutableArray array];
for (int i = 0; i < NUMBER_OF_ITEMS; i++)
{
[items addObject:[NSNumber numberWithInt:i]];
}
carousel1 = [[carousel1 alloc] init];
carousel2 = [[carousel2 alloc] init];
carousel3 = [[carousel3 alloc] init];
carousel4 = [[carousel4 alloc] init];
carousel1.frame = CGRectMake(0, 0, 320, 120);
carousel2.frame = CGRectMake(0, 120, 320, 120);
carousel3.frame = CGRectMake(0, 240, 320, 120);
carousel4.frame = CGRectMake(0, 360, 320, 120);
carousel1.delegate = self;
carousel2.delegate = self;
carousel3.delegate = self;
carousel4.delegate = self;
carousel1.dataSource = self;
carousel2.dataSource = self;
carousel3.dataSource = self;
carousel4.dataSource = self;
[self.view addSubview:carousel1];
[self.view addSubview:carousel2];
[self.view addSubview:carousel3];
[self.view addSubview:carousel4];
//configure carousel
carousel1.type = iCarouselTypeCoverFlow2;
carousel2.type = iCarouselTypeCoverFlow2;
carousel3.type = iCarouselTypeCoverFlow2;
carousel4.type = iCarouselTypeCoverFlow2;
}
but fail with four warnings with out placing the carousels view on the View. Please help me to overcome this problem. Thanks in advance.
Shouldn't you be initialising them with [[iCarousel alloc] init] instead of [[carousel1 alloc] init]?

UIControl touchEvent

i have implemented the following viewDidLoad() Method:
- (void)viewDidLoad {
[super viewDidLoad];
// loading images into the queue
loadImagesOperationQueue = [[NSOperationQueue alloc] init];
AFOpenFlowView *openFlow = self.view;
theControl = [[UIControl alloc] initWithFrame:self.view.frame];
NSString *imageName;
btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(10, 10, 40, 40);
[btn addTarget:self action:#selector(testMethode) forControlEvents:UIControlEventTouchUpInside];
[btn setTitle:#"<<" forState:UIControlStateNormal];
[btn setHidden:YES];
[theControl addSubview:btn];
for (int i=0; i < 10; i++) {
imageName = [[NSString alloc] initWithFormat:#"cover_%d.jpg", i];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
UIImage *aktuellesImage = imageView.image;
UIImage *scaledImage = [aktuellesImage scaleToSize:CGSizeMake(100.0f, 100.0f)];
[openFlow setImage:scaledImage forIndex:i];
// [(AFOpenFlowView *)self.view setImage:scaledImage forIndex:i];
[imageName release];
[aktuellesImage release];
}
[theControl addSubview:openFlow];
[theControl setUserInteractionEnabled:YES];
[(AFOpenFlowView *)self.view setNumberOfImages:10];
}
And the following touchesEnded() Method:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[btn setHidden:NO];
}
But the touchesEnded doesn't work, and the Button will not shown when i touch the picture, does anybody know what is the Problem???
Greetings Marco
Make sure your view has user interaction enabled in order to register touches. This can be set in your View Controller thusly:
self.view.userInteractionEnabled = YES;

Resources