Showing posts with label content. Show all posts
Showing posts with label content. Show all posts

Saturday, November 19, 2016

Swift 3 UITableView Dynamic cell height based on content

Let’s take an example of chat application, where chat bubbles dimensions vary dynamically based on the chatted text.



We can achieve this dynamic size of cell by calculating size of cell based on displaying text font, size and length.This is very tedious. We can achieve this simply using autolayouts and UITableView automatic dimension setting for row height.

First, Take your label and give below constraints. Constraint constants can be of your choice.

  1. top
  2. leading
  3. trailing &
  4. bottom




After that make label as multiline by giving number of Lines as 0 and Line Break as 'Word Wrap'.

Lines - 0
Line Break - Word Wrap






In the code, give the below settings to UITableView.


  
        self.tableViewRank.estimatedRowHeight = 500
      self.tableViewRank.rowHeight = UITableViewAutomaticDimension


That’s it. Now, Table view’s cells will be of dynamic height based on the label’s content.





Hope this post is useful. Feel free to comment incase of any queries.

Monday, August 24, 2015

iOS Box API content fetch limit using Objective c

This article is for iOS developers who are using BOX API in their application. As this is for BOX API users, Here I am not discussing about what is BOX and what it's API gives us. Directly I want to discuss about, How to play with the content limit option in the BOX API.

Here I want to tell like why I am writing this article for such a simple thing. It's look like that :). I used BOX API in one of my applications, where client will setup all his content (folders & files) in the BOX and my iOS app has to fetch the content and has to able to play with the content like upload, download, rename, creation of folders etc.

There were around 120 folders in the BOX that my client has setup. He has perfectly organised those for demo purpose. I have developed this application with a sample BOX account which has around 20 folders like that. I am fetching content using the BOX API's BoxFoldersRequestBuilder and foldersManager classes. I used below code to fetch root folder content from the BOX using BOX API classes. 



BoxFoldersRequestBuilder *folderReqBuilder = [[BoxFoldersRequestBuilder alloc]      
                     initWithQueryStringParameters:@{ @"fields" : @"name,type,
description,tags,id,size,created_at,created_by,modified_at,modified_by,parent"}];   
[[BoxSDK sharedSDK].foldersManager folderItemsWithID:folderID 
                     requestBuilder: folderReqBuilder success:success failure:failure];


As I had only 20 folders in the BOX development account, the above service call to BOX gives me all the 20 folders metadata (name, description etc...). So, I am good for development. But the actual mistake is I didn't check for the default number of assets metadata that BOX gives. Obviously If I have around 1000 items in my BOX, it is not supposed to give me all the assets metadata. 

This content limit option came into picture after sending the application to client. I have used UICollectionView to display the content(files & folders) to the app users. As my client has around 120 assets, he is not able to see all the 120 assets in the UICollectionView. Everytime he is able to see only the first 100 assets. 

We though, it's a rendering issue of the UICollectionView. But it's not. The issue here is by default BOX gives only first 100 assets. So, If we want more content, we need to play with the 'limit' option at the time of requesting the metadata of the root folder content.


For this, I have added limit option in the BoxFoldersRequestBuilder of BOX API as shown below.

BoxFoldersRequestBuilder *folderReqBuilder = [[BoxFoldersRequestBuilder alloc
                     initWithQueryStringParameters:@{ @"fields" : @"name,type,
                                        description,tags,id,size,created_at,created_by,modified_at,
                                        modified_by,parent",@"limit":@150}];
    
[[BoxSDK sharedSDK].foldersManager folderItemsWithID:folderID 
                     requestBuilder: folderReqBuilder success:success failure:failure];

I have added 'limit' key and 150 as the value in the 'initWithQueryStringParameters' of the folderRequestBuilder. That means, I am requesting for the first 150 assets instead of the default 100 assets limit. My request for 150 assets is because I know that my client is having around 150 assets in the root folder. So, the limit value should be based on the number of assets that we want to display. If there are more number of assets, we can go with the pagination option.

Hope this article is useful to iOS BOX API users.
Feel free to comment in case of any queries/concerns.

Friday, August 21, 2015

Objective c SharePoint content fetch soap service

Hope whoever reading this article is familiar with SharePoint authentication using Objective c. If not checkout my post on Objective c SharePoint login service , to get better idea on connecting and getting authenticated to SharePoint Server.

Now, we are able to successfully get authenticated to the SharePoint. So, what's next? Obviously 'Fetching Content' from the SharePoint to display it in our application or for some other purpose. After that you may need operations like listed below.


  •  Create Folder
  •  Upload File
  •  Rename Content
  •  Tagging Files


Let's start with content fetching from the SharePoint. Unlike other CMS systems (like BOX, DropBOX), SharePoint have a structure called 'List'. A List is nothing but a start point where after creating that you can create/upload folders and files. To get better idea on List structure of SharePoint, please go through the SharePoint List structure documentation in Microsoft SharePoint official website.

SharePoint gives you SOAP services for all the operations like I have mentioned above that we need to do on our SharePoint content. This msdn link has the list of end points and soap services names and descriptions that SharePoint provides. As shown in that link the endpoint for getting list of SharePoint items is _vti_bin/lists.asmx. At this location you can see the request and response of the SharePoint SOAP service for GetListItems. GetListItems is the service that we are going to use to get List content from the SharePoint.

Let's have a look at the SOAP service in objective c for fetching list content.




This is the SOAP body that we need to pass at the time of service request. This type of xml SOAP body might be familiar to the developers who have an experience on consuming SOAP services. I am really sorry for putting the code as an image. I tried to copy paste my code but, this xml was colliding with my article html. Once I get a solution for this, I will definitely place the raw code so that If any one need it, they can directly copy paste the code.

Let's see this body in detail and you might have observed that I have used Objective c string placeholders(%@) in this body. First one is for the SharePoint list name. This List is the one on whose content we are interested about in our iOS application and for that only we have connected to SharePoint. The second placeholder is for the folder in that list we are interested about if we are. Here we need to talk about what is folder as we have already given list name, whose content we wanted to fetch. As I said List is the staring point of the directory structurte, where we can have our folders and files. All the time we don't need to fetch the entire list content. Some times we may just need content of one particular folder. In this case we need to mention the folder that we are interested.

Let's see some examples for list names and folder path that we need to parse from the SharePoint URL given to us as these two parameters are very important for the SOAP body.

Example Link - 1:


https://mydomain.com/test/examplelist/Forms/AllItems.aspx?RootFolder=/test/examplelist/fol1/fol2
This is a typical SharePont link structure. All the SharePoint basic urls end with Forms/AllItems.aspx. Here 'examplelist' which is just before the Forms can be taken as the list name that the url is pointing to. 'examplelist' is the list name that we need to put in the SOAP body. The RootFolder parameter of the url tells us the folder in the 'examplelist' List, that we are interested about. So 'fol2' is the target folder name. If you can observe it is at the second level in the list as it is inside of another folder called 'fol1'.
So in this case as the list name and folder values are as shown below.




Example Link - 2:


https://mydomain.com/test/examplelist/Forms/AllItems.aspx?           

In this url there is no RootFolder parameter. It means we are interested directly on the 'examplelist' list content. In this case it's obvious that the folder parameter will be empty. So in this case as the list name and folder values are as shown below.





Example Link - 3:


https://mydomain.com/test/examplelist/Forms/AllItems.aspx?RootFolder=/test/examplelist/fol1     

This example url is same as the url in the Example-1. The only difference is that target folder is at the root level of the examplelist list. 
So in this case as the list name and folder values are as shown below.






Hope now you have got complete picture on the two important values that we have to put in the GetListItems SOAP body(listname and Folder). The next important is the 'rowLimit' value. Let's see what this is. If we have so many folders/files (say around 2000) in our target list or folder whose content we are fetching, Obviously it's a bad practice to fetch all the content and display in the application. So, What we need here is called pagination. This 'rowLimit' parameter helps us for this pagination functionality. If you put 100 as the value, It will give you the 100 rows, means the first 100 assets in the root folder or in the root list. There is an option for querying the items in the target folder or list, which is not that important at this point of time as our mail goal is to first fetch the content.

Now, we understood how to call GetListItems SOAP service of SharePoint to fetch content. It's time to know about the response it throws. 

SharePoint GetListItems service throws a bunch of the below shown xml objects which are nothing but the folders and files in your SharePoint targeted list or folder. In this you can see the folder/file name, author, modified date etc....




Hope this article is useful to SharePoint newbies.


Fell free to comment in case of any queries/concerns.