SWRevealViewController icon indicating copy to clipboard operation
SWRevealViewController copied to clipboard

How to push view on SWRevealViewController Using UInavigationViewController

Open ghost opened this issue 7 years ago • 35 comments

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

ghost avatar Aug 31 '17 04:08 ghost

How is your storyboard?

iDevelopper avatar Aug 31 '17 05:08 iDevelopper

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

ghost avatar Aug 31 '17 07:08 ghost

Just show a screenshot of your Main.storyboard.

iDevelopper avatar Aug 31 '17 07:08 iDevelopper

screen shot 2017-08-31 at 5 27 59 pm

ghost avatar Aug 31 '17 12:08 ghost

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 avatar Aug 31 '17 12:08 iDevelopper

You have to push the SWRController not the agentVC

iDevelopper avatar Aug 31 '17 14:08 iDevelopper

kk Thank you So much sir

ghost avatar Sep 01 '17 03:09 ghost

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

ghost avatar Sep 01 '17 13:09 ghost

Try to embed the controller in a navigation controller.

iDevelopper avatar Sep 01 '17 14:09 iDevelopper

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

iDevelopper avatar Sep 01 '17 14:09 iDevelopper

SWIssue728.zip

iDevelopper avatar Sep 01 '17 16:09 iDevelopper

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

ghost avatar Sep 02 '17 07:09 ghost

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

ghost avatar Sep 02 '17 07:09 ghost

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

iDevelopper avatar Sep 02 '17 07:09 iDevelopper

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 avatar Sep 02 '17 09:09 ghost

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()


}

ghost avatar Sep 02 '17 09:09 ghost

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

iDevelopper avatar Sep 02 '17 16:09 iDevelopper

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

ghost avatar Sep 03 '17 11:09 ghost

Nothing in the file Demo.postman_collection.zip

iDevelopper avatar Sep 03 '17 12:09 iDevelopper

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

ghost avatar Sep 03 '17 12:09 ghost

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?

iDevelopper avatar Sep 03 '17 14:09 iDevelopper

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 .

ghost avatar Sep 04 '17 08:09 ghost

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 avatar Sep 04 '17 08:09 iDevelopper

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?

iDevelopper avatar Sep 04 '17 11:09 iDevelopper

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 avatar Sep 05 '17 05:09 ghost

Demo.postman_collection.zip

FYI, these are the API's @iDevelopper

ghost avatar Sep 05 '17 05:09 ghost

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

iDevelopper avatar Sep 05 '17 06:09 iDevelopper

Could we continue this discussion via mail as we are in an SWRevealViewController issue and it is not the right place for this! ([email protected])?

iDevelopper avatar Sep 05 '17 06:09 iDevelopper

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

iDevelopper avatar Sep 05 '17 08:09 iDevelopper

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 < [email protected]> 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 [email protected] 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 .

ghost avatar Sep 07 '17 11:09 ghost

Yes I just want to continue elsewhere than here, because we are in a SWRevealViewController issue. Can I send you a sample at [email protected] ?

iDevelopper avatar Sep 07 '17 11:09 iDevelopper

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 [email protected] wrote:

Yes I just want to continue elsewhere than here, because we are in a SWRevealViewController issue. Can I send you a sample at [email protected] ?

— 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 .

ghost avatar Sep 08 '17 12:09 ghost

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

iDevelopper avatar Sep 08 '17 12:09 iDevelopper

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

On Fri, Sep 8, 2017 at 6:20 PM, Patrick [email protected] 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 avatar Sep 08 '17 14:09 ghost

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 < [email protected]> wrote:

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

On Fri, Sep 8, 2017 at 6:20 PM, Patrick [email protected] 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 avatar Oct 27 '17 06:10 ghost