John-Lluch / SWRevealViewController

A UIViewController subclass for presenting side view controllers inspired on the FaceBook and Wunderlist apps, done right !
Other
4.52k stars 987 forks source link

How to push view on SWRevealViewController Using UInavigationViewController #728

Open ghost opened 7 years ago

ghost commented 7 years ago

actually i need to push ViewController On swrevealViewControlller . When i am trying to do so It is giving parent as nil. if i am presenting it is working fine. i am new to swift Please help me . presentingVC

let storyboard = UIStoryboard(name: "Main", bundle: nil) let SWRController = storyboard.instantiateViewController(withIdentifier:"SWRevealViewController") switch (userType.loader) {
case .Agent: let destination = storyboard.instantiateViewController(withIdentifier: "Agent") (SWRController as? SWRevealViewController)?.frontViewController = destination self.present(SWRController, animated: true, completion:nil) break pushing VC

let destination = storyboard.instantiateViewController(withIdentifier: "Agent") as!UINavigationController let agentVC = destination.topViewController as! AgentVC (SWRController as? SWRevealViewController)?.frontViewController = agentVC self.navigationController?.pushViewController(agentVC, animated: true)

        break

it gives parent nil please helpme

iDevelopper commented 7 years ago

How is your storyboard?

ghost commented 7 years ago

i didn't get you! i am new to swift can u explain briefly

iDevelopper commented 7 years ago

Just show a screenshot of your Main.storyboard.

ghost commented 7 years ago
screen shot 2017-08-31 at 5 27 59 pm
iDevelopper commented 7 years ago

Sorry can you upload the main.storyborad (you have to compress it in a zip) itself because this is too small in the screenshot.

iDevelopper commented 7 years ago

You have to push the SWRController not the agentVC

ghost commented 7 years ago

kk Thank you So much sir

ghost commented 7 years ago

Main.storyboard.zip if i am pushing i am not getting menu option

screen shot 2017-09-01 at 6 42 15 pm

if i am presenting I am able to see menu button options

screen shot 2017-09-01 at 6 45 53 pm

please help me sir

iDevelopper commented 7 years ago

Try to embed the controller in a navigation controller.

iDevelopper commented 7 years ago

And you don't have a sw_front segue. It should be HomeVC, no?

iDevelopper commented 7 years ago

SWIssue728.zip

ghost commented 7 years ago

Thank You so much !!!!!!!It working Now.

ghost commented 7 years ago

hi sir could you please help me in writing generic handler class URL Request. Thanks in advance.

iDevelopper commented 7 years ago

Can you elaborate? What kind of request? Did you start writing something?

ghost commented 7 years ago

I need to write a ServerRequestHandler which would be generic and which i could reuse in every other ViewControllers of my application. right now am replicating the same set of logic in every set of ViewControllers which is not object oriented.Can you please help me to write that Generic class. BTW i am using URLRequest and URLSession to do so.

ghost commented 7 years ago

func purchaseRequest() {

let urlString = String(format:"http://mandi.connect2community.in/c4t/ledger?queryId=QUERY_DAY_BOOK&args=community_id:7f6a033f-6ae8-4e27-bb58-66238fc3be84,last_update_time:0,account_id:7f6a033f-6ae8-4e27-bb58-66238fc3be84^2017-2018^1,type:SALES,records:20")

    let encodedurl = urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)

let url = URL(string:encodedurl!)

var request = URLRequest(url: url! as URL)

let result = UserDefaults.standard.value(forKey:"session_id")
let ss : String = result as! String
request.httpMethod = "GET"

request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.addValue(("session_id="+ss), forHTTPHeaderField: "Cookie")

request.timeoutInterval = 3

let   task = URLSession.shared.dataTask(with: request as URLRequest!, completionHandler: { (data, response, error) in

if error != nil{
print(error?.localizedDescription as Any)
return
}

do {
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary

print(json ?? "empty from server ")

if let parseJSON = json {
print(parseJSON)

let  success  = Int(json?["errCode"]! as! Double)

if  let resultArray = parseJSON["resource"] as?[[String:AnyObject]]{

    for (index,_) in resultArray.enumerated()
    {

if let vocherno = resultArray[index]["voucher_no"]as? String                    {

    print(vocherno)
    if let eventDate = resultArray[index]["event_date"]as? Int                     {

            let event_date = Constants.getDateStringforMessageVC(dateConveriosn:Double(eventDate))

        print(event_date)
        if let particular = resultArray[index]["particular"]as? String                     {

            print(particular)
            if let accountName = resultArray[index]["account_name"]as? String                     {

                    print(accountName)

                if let amount = resultArray[index]["dr_amount"]as? Int                     {

self.purchaseresult.append(Purchase(vocher: vocherno, eventdate: event_date, particular: particular, accountname: accountName, amount: amount))

print(amount)

                }}}}}}

}
if (success   != 0) {
return
}
else{
DispatchQueue.main.async {
    self.daybooktableview.reloadData()
}
}}
}

catch let error as NSError {
print(error)
}
})

task.resume()

}
iDevelopper commented 7 years ago

Ok, can you give me an URL that will work in a browser? And return a JSON.

ghost commented 7 years ago

These are two demo api's . Please use the first login to get a session id and use that session id in the get request of the second type. Please do open them up in postman rest api client - chrome extension.

FYI, i attach the screenshots of the postman .

And pass this in body of the login api request . as resource as eydlbWFpbF9pZCc6JzkwNjY2NjkzOTMnLCdwYXNzd29yZCc6J21hbmRpJ30=

screen shot 2017-09-03 at 4 56 20 pm screen shot 2017-09-03 at 4 56 35 pm screen shot 2017-09-03 at 4 56 43 pm

Demo.postman_collection.zip

iDevelopper commented 7 years ago

Nothing in the file Demo.postman_collection.zip

ghost commented 7 years ago

You need to open with the Postman application. which is a chrome extension or an app

https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en-GB&utm_source=chrome-ntp-launcher

or https://www.getpostman.com/

import that file in postman

FYI, please check the screenshot attached.

screen shot 2017-09-03 at 6 11 28 pm
iDevelopper commented 7 years ago

Ok got it, I had already Postman but I used it only one or two times. Then there are two JSON structure? One for GET and one for POST request?

ghost commented 7 years ago

Yes exactly. One is for login as u cannot get the request unless and until session is validated. So please do use that POST request - login api for logging in . by which you get the session_id . use this session_id value in the next GET request and get the json object. otherwise you would get an error. @iDevelopper FYI, please check the screenshots .

iDevelopper commented 7 years ago

I wrote a sample to show how you could have a generic API Manager in your application (open the xcworkspace, because it use the SwiftyJSON pod):

APIManagerSample.zip

iDevelopper commented 7 years ago

Now we have to add a parameter to the func data_request:

    func data_request(_ params: String, onSuccess: @escaping(JSON) -> Void, onFailure: @escaping(Error) -> Void)
        var urlString = baseURL + params
        urlString = urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
...

Or add functions for different request types.

And create the different models to return these models instead a json.

What are the models you can receive?

ghost commented 7 years ago

hi @iDevelopper Can you show me how do we pass values and populating Values Into tableview as per the design standards following Design patterns from get request. Maybe i can reuse a single model as per the server architecture as all i do recieve are just string, int, double or boolean values.

ghost commented 7 years ago

Demo.postman_collection.zip

FYI, these are the API's @iDevelopper

iDevelopper commented 7 years ago

So you have two types of request, ledger and community? Then we have to create two object class.

iDevelopper commented 7 years ago

Could we continue this discussion via mail as we are in an SWRevealViewController issue and it is not the right place for this! (patrick.bodet4@wanadoo.fr)?

iDevelopper commented 7 years ago

When you will send me a email, I'll send you a sample!

ghost commented 7 years ago

Hi Patrick,

            can you show me one ViewController  populating  with

Generic URL Request Handler so that i will follow the remaining ViewControllers. Please i am new to swift thats why i am asking these many no of times please Patrick. Please Guide me as a Teacher Please

On Wed, Sep 6, 2017 at 11:20 AM, prasad sanaboina < sanaboinaprasadofficial@gmail.com> wrote:

Respected sir, I already sent the whole project. Can you please check that revert back if u need anything other than that i can send you.

FYI, i reattached the same zip file of the project.

On Tue, Sep 5, 2017 at 2:05 PM, Patrick notifications@github.com wrote:

When you will send me a email, I'll send you a sample!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/John-Lluch/SWRevealViewController/issues/728#issuecomment-327109233, or mute the thread https://github.com/notifications/unsubscribe-auth/AdDSjGmIiymZ-7-bmDZKEJMzXW8k8A_Eks5sfQe2gaJpZM4PIR6u .

iDevelopper commented 7 years ago

Yes I just want to continue elsewhere than here, because we are in a SWRevealViewController issue. Can I send you a sample at sanaboinaprasadofficial@gmail.com ?

ghost commented 7 years ago

Yes please do . anything is fine . I need the SWRevealController in the third screen . So i think that wouldn't be an issue. But i need to follow the MVC pattern w.r.t it .

On Thu, Sep 7, 2017 at 5:25 PM, Patrick notifications@github.com wrote:

Yes I just want to continue elsewhere than here, because we are in a SWRevealViewController issue. Can I send you a sample at sanaboinaprasadofficial@gmail.com ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/John-Lluch/SWRevealViewController/issues/728#issuecomment-327777547, or mute the thread https://github.com/notifications/unsubscribe-auth/AdDSjIiNEPHAUeLwE-vFas8DSdYsVzcDks5sf9m0gaJpZM4PIR6u .

iDevelopper commented 7 years ago

I sent you a sample yesterday. APIManagerSample. Did you receive it?

ghost commented 7 years ago

Oh yeah, I recieved . Sorry i missed out that email. Thank you.

On Fri, Sep 8, 2017 at 6:20 PM, Patrick notifications@github.com wrote:

I sent you a sample yesterday. APIManagerSample. Did you receive it?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/John-Lluch/SWRevealViewController/issues/728#issuecomment-328094353, or mute the thread https://github.com/notifications/unsubscribe-auth/AdDSjAYRt0oM0ml_3mXSjCyURa-oTY9Fks5sgTf5gaJpZM4PIR6u .

ghost commented 7 years ago

Hi Patrick,

Thanks for the help till now. I am very new to iOS Swift. I want to code like Professionals with respective code optimisation. Can you help me in that.

On Fri, Sep 8, 2017 at 7:30 PM, prasad sanaboina < sanaboinaprasadofficial@gmail.com> wrote:

Oh yeah, I recieved . Sorry i missed out that email. Thank you.

On Fri, Sep 8, 2017 at 6:20 PM, Patrick notifications@github.com wrote:

I sent you a sample yesterday. APIManagerSample. Did you receive it?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/John-Lluch/SWRevealViewController/issues/728#issuecomment-328094353, or mute the thread https://github.com/notifications/unsubscribe-auth/AdDSjAYRt0oM0ml_3mXSjCyURa-oTY9Fks5sgTf5gaJpZM4PIR6u .