<pre><code class="swift">
var page = 0
var searchPage = 0
var loadAble = true
var loadEnd = false
var loadSearchEnd = false
var shopList : NSMutableArray!
var searchShopList : NSMutableArray!
func searchAllShopList(keyword:String) {
loadAble = false
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let process = JSONNetwork()
var arr = ["manager" : "shop", "method" : "search_shop_all", "uid" : uid, "token": token, "page" : String(searchPage), "latitude" : appDelegate.latitude, "longitude" : appDelegate.longitude, "keyword" : keyword]
process.delegate = self
process.jsonProccess(arr, code: NetworkCode().GET_SEARCH_SHOP_ALL)
}
func searchAllShopList(keyword:String) {
loadAble = false
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let process = JSONNetwork()
var arr = ["manager" : "shop", "method" : "search_shop_all", "uid" : uid, "token": token, "page" : String(searchPage), "latitude" : appDelegate.latitude, "longitude" : appDelegate.longitude, "keyword" : keyword]
process.delegate = self
process.jsonProccess(arr, code: NetworkCode().GET_SEARCH_SHOP_ALL)
}
func returnJSON(data: NSDictionary, code: Int) {
if NetworkCode().GET_SHOP_ALL==code{
var returnData : NSDictionary = data.valueForKey("data") as! NSDictionary
if(shopList == nil){
shopList = returnData.valueForKey("shop_list") as? NSMutableArray
}else{
var addListShop = returnData.valueForKey("shop_list") as? NSMutableArray
if addListShop?.count != 0{
shopList.addObject(addListShop!)
}else{
loadEnd = true
}
}
page++
NSOperationQueue.mainQueue().addOperationWithBlock {
self.tableView.reloadData()//테이블뷰 재로딩
self.loadAble = true
}
if NetworkCode().GET_SHOP_ALL==code{
var returnData : NSDictionary = data.valueForKey("data") as! NSDictionary
if(shopList == nil){
shopList = returnData.valueForKey("shop_list") as? NSMutableArray
}else{
var addListShop = returnData.valueForKey("shop_list") as? NSMutableArray
if addListShop?.count != 0{
shopList.addObject(addListShop!)
}else{
loadEnd = true
}
}
page++
NSOperationQueue.mainQueue().addOperationWithBlock {
self.tableView.reloadData()//테이블뷰 재로딩
self.loadAble = true
}
else if NetworkCode().GET_SEARCH_SHOP_ALL==code {
var returnData : NSDictionary = data.valueForKey("data") as! NSDictionary
if(searchShopList == nil){
searchShopList = returnData.valueForKey("shop_list") as? NSMutableArray
}else{
var addListShop = returnData.valueForKey("shop_list") as? NSMutableArray
if addListShop?.count != 0{
searchShopList.addObject(addListShop!)
}else{
loadSearchEnd = true
}
}
searchPage++
NSOperationQueue.mainQueue().addOperationWithBlock {
self.searchDisplayController?.searchResultsTableView.reloadData()//SearchBar 결과테이블뷰 재로딩
self.loadAble = true
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell : MainTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("MainTableViewCell") as! MainTableViewCell
var cellData : NSDictionary!
if(tableView == self.searchDisplayController!.searchResultsTableView){
cellData = searchShopList[indexPath.row] as! NSDictionary
}else{
cellData = shopList[indexPath.row] as! NSDictionary
}
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
if(tableView == self.searchDisplayController!.searchResultsTableView){//검색 결과시
if(searchShopList.count == (indexPath.row+1)){
if(loadAble && !loadSearchEnd){
searchAllShopList(searchBar.text)
}
}
}else{//기본
if(shopList.count == (indexPath.row+1)){
if(loadAble && !loadEnd){
getAllShopList()
}
}
}
}
</code></pre>
'Programming > Swift' 카테고리의 다른 글
Delegate (0) | 2015.06.01 |
---|---|
KAKAO Link 방법. 안드로이드, 아이폰, 아이패드URL 각 앱스토어 연결 URL (0) | 2015.05.31 |
파싱받은 웹주소버튼 입력시 사파리로 띄우기 (0) | 2015.05.26 |
ㄴㅁㅇㅇ (0) | 2015.05.25 |
뒤로가기버튼 (0) | 2015.05.15 |