samedi 27 juin 2015

how to make a uitableview know about where to scroll for uncreated views yet

I have a UITableView which has up to 600 items in it. They are split between headers and items (like 30 headers of 15-20 items each). It is a catalog and has to mimick the printed catalog.

There is also a navigation pop-up view that shows only the headers that a user can overlay to the main table view. It is represented like this:

header
 \subheader
header2
\subheader
  \subheader

And our code for navigating is like this:

  func tapOnMenuHeaderView(recognizer: UITapGestureRecognizer)
  {
    self.hideModalNavigation()
    self.mainTV.reloadData()
    self.mainTV.scrollToRowAtIndexPath(NSIndexPath(forRow: self.menuHeaderPositions[recognizer.view!.tag]!, inSection: 0), atScrollPosition: UITableViewScrollPosition.Top, animated: true)
  }

However, it doesn't go to the right place many times. It seems to always be short and gets less accurate the further down you go. Is this a limitation to scrollRowAtIndexPath and is there a way I could force a full reload or something? The only way I could get this to work was to remove using a tableview and do everything as UIViews and just increment it in a scroll view. How would I make it so that our overlay navigation scrolls to the correct place?

Add Selfie Stick Support To iOS App

I am looking to add support for a "Selfie Stick Remote" to my upcoming iOS app. This question was already asked in the form of How to detect click event of connected Bluetooth peripheral device (Selfie stick)? but for Android, not iOS.

Specifically I am looking for it to work with the bluetooth devices (like this one http://ift.tt/1NnSiqf).

randomly change image of buttons and decelerate changing

i have 2 buttons.

they are called _rightButtonPressed and _leftButtonPressed. They have an background image named "blackBackground". When they are clicked, the background image is changed to "whiteBackground".

Ok. Now i want to make a third button, that changes the background image at first _rightButtonPressed to "white", then "black", then _leftButtonPressed to "white", then "black" and so on. This change have to decelerate to the end. At least, it should be randomly stops at a button with "white" background image and click the button. I hope its comprehensible.

I have no idea, how i can do this...

How to set the title text color of UIButton?

I tried changing the colors of the text for a button, but it's still staying white.

isbeauty = UIButton()
isbeauty.setTitle("Buy", forState: UIControlState.Normal)
isbeauty.titleLabel?.textColor = UIColorFromRGB("F21B3F")
isbeauty.titleLabel!.font = UIFont(name: "AppleSDGothicNeo-Thin" , size: 25)
isbeauty.backgroundColor = UIColor.clearColor()
isbeauty.layer.cornerRadius = 5
isbeauty.layer.borderWidth = 1
isbeauty.layer.borderColor = UIColorFromRGB("F21B3F").CGColor
isbeauty.frame = CGRectMake(300, 134, 55, 26)
isbeauty.addTarget(self,action: "first:", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(isbeauty)

I also tried changing it the red, black, blue, but nothing is happening.

Days countdown iOS swift

My app requires that I start countdown of days from first launch. If someone launch my app for the first time I want to count day 1 after 12 midnight (using the device clock of course) and then day2 ... and perform an action after the 21st day. It shouldn't matter if the person close the app or switch off phone. When the app come back up, it should automatically detect how many days have passed.

Does anyone have an idea how to realise that ? . I am thinking of NStimer but kind of confuse.

MagicalRecord findByAttribute returning inverse relationship documents issue

I'm having an issue figuring out how to model/fetch items with Core Data and MagicalRecord. I have two entities, User and Message, which both have inverse relationships to each other:

User Entity

Relationship    Destination    Inverse    Type
-------------------------------------------------
messages        Message        user       To Many

Message Entity

Relationship    Destination    Inverse    Type
-------------------------------------------------
user            User           messages   To One

Issue

When fetching messages by a given user, MagicalRecord is returning 2x the number of records since it's matching attributes at the user and user.messages.user keyPaths:

- (NSArray *)fetchMessagesByUser:(NSString *)identifier {

    // returning 2x the records it should
    return [Message MR_findByAttribute:@"user.identifier" withValue:identifier];
}

Should I change the way I'm using MagicalRecord or is there a fundamental issue with my Core Data model?

When programatically creating a ViewController, how can I set its view to be of type SKVIew?

I am developing a game in iOS on XCode. I have several SKScenes each associated with a UIViewController class. So in each of the view controller's viewDidLoad, I create

SKView *skView = (SKView *)self.view
SKScene * scene = [whateverSKScene sceneWithSize:skView.bounds.size]
[skView present scene]

I want to avoid the storyboard. However, when I presentViewController from the first view controller to the next, the app crashes at the line "[skView present scene]" because it thinks the new view controller's view is still UIView ('-[UIView presentScene:]: unrecognized selector sent to instance).

How can I fix this? Specifically, when creating the 2nd view controller (programatically), how can I change its view to be of type SKview not UIview? (I should note I want the scenes to be 1:1 with view controllers because almost all of them are popups like a pause-menu pop up over game play or settings pop up etc)