I am using NIDropworn in a strip of view the problem is the drop-down table is coming over another view which I have just placed below the drop-down view.
I am unable to select and and do any operation on the drop down table .
Is there a way that I can add the drop-down in the second view.
now the dropdown is coming on the small strip of view.
For example: I am having the dropDown menu in the header of a page which is view1.and the dropdown table is coming on the body which is view2.
You may not have added the NIDropDown in your view.
- (IBAction)btn_click:(id)sender {
NSArray * arr = [[NSArray alloc] init];
arr = [NSArray arrayWithObjects:#"None",#"Name",#"Date",nil];
// NSArray * arrImage = [[NSArray alloc] init];
if(dropDown == nil) {
CGFloat f = 130;
dropDown = [[NIDropDown alloc]showDropDown:sender :&f :arr :nil :#"down"];
dropDown.delegate = self;
dropDown.userInteractionEnabled=YES;
[self.viewBelowDD addSubview:dropDown]; // may be missing this line
[self.viewBelowDD bringSubviewToFront:dropDown];
}
else {
[dropDown hideDropDown:sender];
[self rel];
}
}
Hope that helps. Let me know if this doesn't work.
Related
I have constructed the following method fetchLastFiveLogins and the method successfully adds the users avatar to the _avatarButton. However, when a user taps the avatar it calls the fillUserName method. That part is working, but I can't figure out how to fill the _textfieldUsername with the username associated with the avatar. Below is a snippet of the fetchLastFiveLogins method.
// sort / filter "results" to display the last five "lastLogin(s)"
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:#"lastLogin" ascending:NO];
NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptor, nil];
[request setFetchLimit:5];
[request setSortDescriptors:sortDescriptors];
// fetch records and handle error
NSError *error;
NSArray *results = [_managedObjectContext executeFetchRequest:request error:&error];
if (!results) {
// handle error
// also if there is login data handle error so app doesn't crash
}
Account *anAccount;
// create a stock image
UIImage *btnImage = [UIImage imageNamed:#"HomeBrewPoster1.jpg"];
NSMutableArray *avatars = [NSMutableArray arrayWithCapacity:5];
for ( anAccount in results) {
NSLog(#"results%#",anAccount.lastLogin);
if(anAccount.lastLogin) {
NSLog(#"anAccount.lastLogin = %#, by:%#",anAccount.lastLogin,anAccount.username);
if (anAccount.avatar != nil) {
UIImage *avatarImg = [UIImage imageWithData:anAccount.avatar ];
[avatars addObject:avatarImg];
}
else {
[avatars addObject:btnImage];
}
}
}
NSLog(#"avatars array%lu",(unsigned long)avatars.count);
for ( NSInteger i = 0; i < 4; i++) {
// Check that we have enough logins
if (i < results.count) {
NSLog(#"avatars =%#",avatars[i]);
CGFloat staticX = 0;
CGFloat staticWidth = 80;
CGFloat staticHeight = 80;
CGFloat staticPadding = 5;
_avatarButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// the last two values control the size of the button
_avatarButton.frame = CGRectMake(0, 0, 80, 80);
[_avatarButton setFrame:CGRectMake((staticX + (i * (staticHeight + staticPadding))),5,staticWidth,staticHeight)];
// make corners round
_avatarButton.layer.cornerRadius = 40; // value varies -- // 35 yields a pretty good circle.
_avatarButton.clipsToBounds = YES;
// assign method / action to button
[_avatarButton addTarget:self action:#selector(fillUserName) forControlEvents:UIControlEventTouchDown];
[_avatarButton setBackgroundImage:[avatars objectAtIndex:i] forState:UIControlStateNormal];
NSLog(#"avatarImage = %#",[_avatarButton backgroundImageForState:UIControlStateNormal]);
[_avatarScroll addSubview:_avatarButton];
}
}
}
Step 1: Make the fillUserName method take the parameter fillUserName:(id) sender, so that the method will be passed the button that was pressed. You'll want to tweak the addTarget so that it uses #selector(fillUserName:) (with the colon at the end).
Step 2: You'll need to be able to distinguish which of the buttons was pressed. Often people use the tag property of UIButton (and other controls) to distinguish the buttons. If you set the tag to be the array index of the result, then the button with tag 0 is the 0th entry in your results array. See this question: How do i set and get UIButtons' tag? for some code samples.
Step 3: Ensure that you've held on to references to the results array, so that you can access it from the fillUserName: method.
Update: As I mention in my comment, below, a solution that makes use of blocks seems like a much better solution, and some folks have written some nice code to enable that.
I'm new to objective c and need some help. I've only one view controller which should show when as default an array called factbook. However I'd like to change the array by an alert validation. So that if the user would like to see sport he could just click on sport on the alert view and the current view controller would change the theme name to sport, the background color to the color scheme i'd like for the sport theme and the text to the sport facts array. Every help is welcome!
- (void)viewDidLoad {
[super viewDidLoad];
// init for displaying facts
self.factBook = [[FactBook alloc] init];
self.colorWheel = [[ColorWheel alloc] init];
self.view.backgroundColor = [self.colorWheel randomColor];
self.funFactLabel.text = [self.factBook randomFact];
}
- (IBAction)showFunFact:(UIButton *)sender {
self.view.backgroundColor = [self.colorWheel randomColor];
funFactLabel.text = [self.factBook randomFact];
}
- (IBAction)changeTheme:(UIButton *)sender {
// to sport
[changeThemeNotification addButton:#"change to sport" validationBlock:^BOOL{
BOOL passedValidation = true;
return passedValidation;
} actionBlock:^{
// segue to sport
self.themeName.text = #"Sport";
self.sportFactBook = [[SportFactBook alloc] init];
self.sportColorWheel = [[SportColorWheel alloc] init];
// not working
// self.funFactLabel = [self.sportFactBook randomSportFact];
self.view.backgroundColor = [self.sportColorWheel randomColor];
}];
//...
}
Assuming that this comment
// not working
// self.funFactLabel = [self.sportFactBook randomSportFact];
is the part you want to fix. If you are updating a label, just change its text
self.funFactLabel.text = [self.sportFactBook randomSportFactText];
randomSportFactText should return an NSString*.
If you set the output to a new label object, that doesn't update the view -- it just disassociates the outlet from the label in the view.
If you want to change just the backgroundColor, you can do that too:
self.funFactLabel.backgroundColor = [UIColor redColor];
In my table cells, there is a button that displays a drop-down menu when you click on it. The problem is, the drop-down menu exceeds the height of the cell and bleeds into the cell below.
In that case, if I click the item in the drop-down, it actually acts as I clicked the cell below.
I tried using the code below but it doesn't seem to work.
[super bringSubviewToFront:dropDown];
[super willMoveToSuperview:dropDown];
The function that shows the drop-down is defined in the custom class for the table cell:
- (IBAction)eventAction:(id)sender {
NSArray * arr = [[NSArray alloc] init];
arr = [NSArray arrayWithObjects:#"Hello 0", #"Hello 1",nil];
NSArray * arrImage = [[NSArray alloc] init];
arrImage = [NSArray arrayWithObjects:[UIImage imageNamed:#"apple.png"], [UIImage imageNamed:#"apple2.png"], nil];
if(dropDown == nil) {
CGFloat f = 100;
dropDown = [[NIDropDown alloc]showDropDown:sender :&f :arr :arrImage :#"down"];
dropDown.delegate = self;
dropDown.layer.zPosition = 1;
[super bringSubviewToFront:dropDown];
[super willMoveToSuperview:dropDown];
}else {
[dropDown hideDropDown:sender];
[self rel];
}
}
Any help is greatly appreciated!!
Thank you!!
Rather than being a case of views being on top of each other, I think it might be that the touch is being interpreted by the table cell below as well.
Try disabling user interaction in the table view when the eventAction is fired.
tableView.userInteractionEnabled = NO;
And then turn it back on when the drop down view is dismissed.
I have 6 UIButtons set up in my UIView, all in the exact same location. What I want to do, is to swipe from left to right or right to left, in order to go through the buttons.
I have the UIGestures all set up and working on the view, I am just not sure the best way to go about cycling through these UIButtons.
I was thinking that it could be simple enough to tag each UIButton and HIDE all but one, but am not sure about the best way to loop through these.
Just put them in an NSMutableArray and whatever button is at index 0 is the visible one, as they swipe you'd remove the button at index 0, set it to hidden = YES and add it to the end of the array then set the button at index 0's hidden = NO.
Assuming you're using ARC, inside your class' implementation (.m) file:
#interface MyFancyButtonClass () {
NSMutableArray *_swipeButtons;
}
inside your viewDidLoad:
_swipeButtons = [NSMutableArray arrayWithObjects:buttonOne, buttonTwo, buttonThree, buttonFour, nil];
buttonOne.hidden = NO;
buttonTwo.hidden = buttonThree.hidden = buttonFour.hidden = YES;
inside your gestureRecognizer:
UIButton *currentVisibleButton = [_swipeButtons firstObject];
UIButton *nextVisibleButton = [_swipeButtons objectAtIndex:1];
[_swipeButtons removeObject:currentVisibleButton];
[_swipeButtons addObject:currentVisibleButton];
currentVisibleButton.hidden = YES;
nextVisibleButton.hidden = NO;
Create a NSMutableArray like this:
NSMutableArray * buttons = [[NSMutableArray alloc] init];
[buttons addObject:button1];
[buttons addObject:button2];
[buttons addObject:button3];
[buttons addObject:button4];
[buttons addObject:button5];
Save this array to a property like this
self.buttons = buttons;
Store the currentButton Like this:
int currentButton = 0;
Get the current button like this:
UIButton * currentSelectedButton = buttons[currentButton];
Cycle through the buttons like this:
UIButton * currentSelectedButton = buttons[currentButton];
currentSelectedButton.hidden = YES;
currentButton++;
if (currentButton >= self.buttons.count)
currentButton = 0;
currentSelectedButton = buttons[currentButton];
currentSelectedButton.hidden = NO;
How can I pass data from UINavigationController to The root UITableViewController?
I have implemented the ECSlidingViewController (https://github.com/edgecase/ECSlidingViewController). User selects one of the cells in the menu that correspond to different urls I want to display information from on my tableView that sitts on top of the UINavigationController. (u know the default combination that u get my dragging UINavigationController to ur storyboard). I am able to get the data from the sliding menu to my navigationController now I am trying to pass that same info on my tableview?
In my menu I have:
UINavigationController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"NavigationTop"];
newTopViewController = [(NavigationTopViewController*)newTopViewController initWithCinema:self.myCinema];
In UINaviationController:
- (id)initWithCinema:(Cinema *)cinema {
self = [super init];
if(self) {
_myCinema = [[Cinema alloc] init];
_myCinema = cinema;
}
return self;
}
- (void) viewDidLoad {
[super viewDidLoad];
// this log works I get the info to here.
NSLog(#"url(navigation):%#", self.myCinema.cinemaURL);
//MoviesTableViewController *moviesTableViewController = [[MoviesTableViewController alloc] initWithCinema:self.myCinema];
//UITableViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"MoviesTable"];
//NavigationTopViewController *newTopViewController = [[NavigationTopViewController alloc] initWithCinema:self.myCinema];
//newTopViewController = [(MoviesTableViewController *)newTopViewController initWithCinema:self.myCinema];
//[self performSegueWithIdentifier:nil sender:self.myCinema];
[self prepareForSegue:nil sender:self.myCinema.cinemaURL];
}
In my UITableView:
- (void)setCinema:(Cinema *)cinema {
// works here too
NSLog(#"Table(setCinema):%#", cinema.cinemaURL);
self.myCinema = [[Cinema alloc] init];
if(!cinema) {
cinema.cityIndex = kAstanaIndex;
cinema.name = kKeruen;
cinema.nameForText = kKeruenText;
cinema.cinemaURL = kKeruenURL;
cinema.cinemaURLTomorrow = kKeruenURLtomorrow;
}
self.myCinema = cinema;
// works here too!!!
NSLog(#"Table(myCinema):%#", self.myCinema.cinemaURL);
}
However its gone in viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
// set delegate to self
self.tableView.delegate = self;
// set loading theater's url
// does not work here: I GET NULL !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
NSLog(#"url(moviesTable):%#", self.myCinema.cinemaURL);
_model = [[MovieModel alloc] initWithURL:self.myCinema.cinemaURL];
}
None of the methods I have tried (commented in Navigation worked...) at least for me. Please give me any suggestions. Thank you in advance.
UINavigationController does not hold any data, but rather a stack of view controllers. I'd recommend you check out frameworks such as the free Sensible TableView. The framework will automatically handle detail view generation and passing data between them. Saves me tons of development time in my projects.